![如何理解 `sed -n '/^#n_sns\tn_loc/,/^[^0-9]/ p' $log_file | grep -E '^[0-9]' > $log_file.sns_p_loc`?](https://linux22.com/image/11682/%E5%A6%82%E4%BD%95%E7%90%86%E8%A7%A3%20%60sed%20-n%20'%2F%5E%23n_sns%5Ctn_loc%2F%2C%2F%5E%5B%5E0-9%5D%2F%20p'%20%24log_file%20%7C%20grep%20-E%20'%5E%5B0-9%5D'%20%3E%20%24log_file.sns_p_loc%60%3F.png)
我正在阅读教程,有一个 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
首先由 完成。