Fork me on GitHub

awk命令配合while read line 处理linux多行输出

command命令的输出作为read循环的输入,这种结构常用于处理超过一行的输出常见用法有:
command | while read line
do

done

举个栗子
test目录下面有3个文件

 

 

 

我想输出
aa.txt is a txt file.
bb.txt is a txt file.
cc.txt is a txt file.

首先去掉total 0

 

 

然后使用awk命令找到需要的列

 

 


然后使用while read line 执行命令输出我们想要的效果

 

 


或者我们可以整合成一行

ll|grep -v totel|awk '{print $2}'|while read line; do echo $line is a txt; done

 

 

posted @ 2021-09-28 19:29  超级花心大萝卜  阅读(800)  评论(0)    收藏  举报