SED / AWK:从文本流中提取模式 [英] sed/awk: Extract pattern from text stream
本文介绍了SED / AWK:从文本流中提取模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
2011-07-01 ... /home/todd/logs/server_log_1.log ...
2011-07-02 ... /home/todd/logs/server_log_2.log ...
2011-07-03 ... /home/todd/logs/server_log_3.log ...
我有一个文件看起来像上面。我想从它输出的文件名作为解压到STDOUT:
I have a file looks like the above. I want to extract the file names from it and output to STDOUT as:
server_log_1.log
server_log_2.log
server_log_3.log
有人能帮忙吗?谢谢!
Could someone help? Thanks!
文件名模式是server_log_xxx.log,并且只在一条线上出现一次。
The file name pattern is server_log_xxx.log, and it only occurs once in a line.
推荐答案
假设XXX占位符是唯一的数字:
Assuming the "xxx" placeholder is only digits:
grep -o 'server_log_[0-9]\+\.log'
这篇关于SED / AWK:从文本流中提取模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文