文件内容如下:
xx-ww-test12-y36 | FAILED | rc=2 >>
ls: cannot access /hello/disk*/test12_v8/hello/test12_v8_002/04A/268/1E8: No such file or directorynon-zero return code
xx-ww-test12-y37 | FAILED | rc=2 >>
ls: cannot access /hello/disk*/test12_v8/hello/test12_v8_002/04A/268/1E8: No such file or directorynon-zero return code
xx-ww-test12-y38 | SUCCESS | rc=0 >>
-rw-rw-r-- 2 test hello 76369 Oct 9 10:58 /hello/disk7/test12_v8/hello/test12_v8_002/04A/268/1E8
xx-ww-test12-y47 | FAILED | rc=2 >>
ls: cannot access /hello/disk*/test12_v8/hello/test12_v8_002/04A/268/1E8: No such file or directorynon-zero return code
xx-ww-test12-y46 | FAILED | rc=2 >>
ls: cannot access /hello/disk*/test12_v8/hello/test12_v8_002/04A/268/1E8: No such file or directorynon-zero return code
xx-ww-test12-y48 | SUCCESS | rc=0 >>
-rw-rw-r-- 2 test hello 56288 Oct 12 13:27 /hello/disk7/test12_v8/hello/test12_v8_002/04A/268/1E8
linux shell要把SUCCESS这一行的下一行打印出来
要在 Linux shell 中打印出 SUCCESS
行的下一行,可以使用 awk
或 grep
结合 sed
来实现。以下是两种常见方法:
方法 1:使用 awk
awk '/SUCCESS/{getline; print}' your_file.txt
方法 2:使用 grep
和 sed
grep -A 1 'SUCCESS' your_file.txt | tail -n 1
解释:
-
方法 1:
awk '/SUCCESS/{getline; print}'
:/SUCCESS/
匹配包含SUCCESS
的行。getline
读取下一行。print
打印出这一行。
-
方法 2:
grep -A 1 'SUCCESS'
:-A 1
选项表示打印SUCCESS
行及其后面的一行。
tail -n 1
只打印最后一行,即SUCCESS
行的下一行。
这两种方法都会输出你希望的内容,即 SUCCESS
行的下一行。确保将 your_file.txt
替换为你的实际文件名。