如何理解 `sed -n '/^#n_sns\tn_loc/,/^[^0-9]/ p' $log_file | grep -E '^[0-9]' > $log_file.sns_p_loc`?

如何理解 `sed -n '/^#n_sns\tn_loc/,/^[^0-9]/ p' $log_file | grep -E '^[0-9]' > $log_file.sns_p_loc`?

我正在阅读教程,有一个 sed 命令:

sed -n '/^#n_sns\tn_loc/,/^[^0-9]/ p' $log_file | grep -E '^[0-9]' > $log_file.sns_p_loc

我看不懂,谁能给我解释一下?或者是否有什么地方错了?

答案1

这有帮助吗?

sed -n '                # run sed but don't print by default
/^#n_sns\tn_loc/,       # from match 1
/^[^0-9]/               # to match 2
 p'                     # print

您的特别问题:

^                       # anchor at begin  of line
[                       # opens a "bracket expression" which normally matches any single character from the list
^                       # a leading ^ makes it match any single character NOT from the list.
0-9                     # character range, only digits 
]                       # close "bracket expression"

grep似乎是多余的;它的操作(以数字开头的打印行)可以sed首先由 完成。

相关内容