首页 > 解决方案 > 遍历标准输入鱼(上下文:按流派 grep 过滤音乐文件)

问题描述

我有这个:

for file in **/*.ogg;  
    if ffprobe "$file" 2>&1 | sed -E -n 's/^ *GENRE *: (.*)/\1/p' | grep -q "$argv"; 
        echo "$file"
    else
    end
end

但我想把它变成一个函数,它将文件名列表作为标准输入:

$ find . -maxdepth 1 -not -type d -exec du -h {} + | cut -f2 | filterByGenre Classical

标签: fish

解决方案


你可以做

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

推荐阅读