【发布时间】:2021-01-16 23:30:08
【问题描述】:
我有一个文件,其中包含以下目录的路径名:
~/subdirectory1/subdirectory2/.../a/
~/subdirectory1/subdirectory2/.../b/
...
~/subdirectory1/subdirectory2/.../z/
想要的步骤:
- 打开文本文件
- 取一行
- 将其传递给命令“ls”
- 管道输出并排除所有出现的结尾“jpg”或“JPG”
- 将结果路由到新的文本文件(例如“_command_output.log”)
我在玩xargs,但无法让它运行。
这是我目前所拥有的:列出文件并排除所有“jpg”或“JPG”结果。
ls ~/subdirectory1/subdirectory2/.../a/ | awk '!/(jpg|JPG)/'
我把它放到一个循环中:
for i in $(cat ~/textfile-with-pathnames.txt) do
#do your stuff to $i here
##xargs ls;
ls ${i} | awk '!/(jpg|JPG)/'
done
再试一次:
cat ~/textfile-with-pathnames.txt | while read line;
do
ls "$line" | awk '!(jpg|JPG)';
done
如何为文件中的每一行运行一个参数并将文件内容用作参数/参数?
【问题讨论】:
标签: linux bash shell scripting