迭代标准输入鱼(上下文:按流派 grep 过滤音乐文件)
iterate over stdin fish (context: filter music files by genre grep)
我有这个:
for file in **/*.ogg;
if ffprobe "$file" 2>&1 | sed -E -n 's/^ *GENRE *: (.*)//p' | grep -q "$argv";
echo "$file"
else
end
end
但我想把它变成一个函数,它将文件名列表作为标准输入:
$ find . -maxdepth 1 -not -type d -exec du -h {} + | cut -f2 | filterByGenre Classical
你可以
function filterByGenre
while read line
do stuff with $line
end
end
或
function filterByGenre
set listOfLines (cat)
for line in $listOfLines
do stuff with $line
end
end
我有这个:
for file in **/*.ogg;
if ffprobe "$file" 2>&1 | sed -E -n 's/^ *GENRE *: (.*)//p' | grep -q "$argv";
echo "$file"
else
end
end
但我想把它变成一个函数,它将文件名列表作为标准输入:
$ find . -maxdepth 1 -not -type d -exec du -h {} + | cut -f2 | filterByGenre Classical
你可以
function filterByGenre
while read line
do stuff with $line
end
end
或
function filterByGenre
set listOfLines (cat)
for line in $listOfLines
do stuff with $line
end
end