i / p文件:
a.txt
9842,5003,a,a,100
9942,5003,a,a,100
9852,5003,a,a,100
98456,5003,a,a,100
9742,5003,a,a,100
b.txt
7842,5003,a,a,100
7942,5003,a,a,100
7852,5003,a,a,100
98456,5003,a,a,100
7742,5003,a,a,100
c.txt
8842,5003,a,a,100
9842,5003,a,a,100
8852,5003,a,a,100
88456,5003,a,a,100
8742,5003,a,a,100
要完成的操作: 我需要grep上面输入文件中的特定行(a.txt,b.txt& c.txt) 输出行应包含所有字段,并且filname应包含最后一个字段
o / p格式: 说我grep行以“9”开头表示将需要以下格式输出
9842,5003,a,a,100,a.txt
9942,5003,a,a,100,a.txt
9852,5003,a,a,100,a.txt
98456,5003,a,a,100,a.txt
9742,5003,a,a,100,a.txt
98456,5003,a,a,100,b.txt
9842,5003,a,a,100,c.txt
答案 0 :(得分:1)
grep -H '^9' a.txt b.txt c.txt | awk -F : '{print $2","$1;}'
Grep表示以9开头的行,使用-H标志打印文件名,然后使用awk将其转换为您想要的格式。 awk的-F标志将字段分隔符更改为“:”
答案 1 :(得分:0)
你可以使用一个awk命令,不需要grep。 grep和awk是补充。
awk '/^9/{print $2","$1","FILENAME}' [abc].txt