大家好,请帮助我,我正试图得到以下输出,所以基本上我有2个输入文件,我们只需要共同的:名称从两个输入文件以及下面的行。名称/的/文件行。
到目前为止,我已经尝试过:
awk '/:name1/{flag=1} flag;/ /{flag=0}' /path/of/input/file1
输出:
:name1
./name/of/file [logfile] [ error in file coming since Day : 1 ]
但它只打印了第一行。
- 输入文件1:**
:name1
./name/of/file [logfile] [ error in file coming since Day : 1 ]
./name/of/file [logfile] [ error in file coming since Day : 1 ]
:name2
./name/of/file [logfile] [ error in file coming since Day : 1 ]
:name3
./name/of/file [logfile] [ error in file coming since Day : 24 ]
./name/of/file [logfile] [ error in file coming since Day : 24 ]
:name4
./name/of/file [logfile] [ error in file coming since Day : 3 ]
./name/of/file [logfile] [ error in file coming since Day : 3 ]
./name/of/file [logfile] [ error in file coming since Day : 3 ]
./name/of/file [logfile] [ error in file coming since Day : 3 ]
:name5
./name/of/file [logfile] [ error in file coming since Day : 6 ]
./name/of/file [logfile] [ error in file coming since Day : 6 ]
- 输入文件2:**
:name1
:name3
:name4
- 所需输出文件**:
:name1
./name/of/file [logfile] [ error in file coming since Day : 1 ]
./name/of/file [logfile] [ error in file coming since Day : 1 ]
:name3
./name/of/file [logfile] [ error in file coming since Day : 24 ]
./name/of/file [logfile] [ error in file coming since Day : 24 ]
:name4
./name/of/file [logfile] [ error in file coming since Day : 3 ]
./name/of/file [logfile] [ error in file coming since Day : 3 ]
./name/of/file [logfile] [ error in file coming since Day : 3 ]
./name/of/file [logfile] [ error in file coming since Day : 3 ]
2条答案
按热度按时间bxgwgixi1#
一种
awk
方法:这将产生:
2eafrhcq2#
输出也可以缩进: