Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed/awk: Extract pattern from text stream

Tags:

grep

bash

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 ...

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!

The file name pattern is server_log_xxx.log, and it only occurs once in a line.

like image 800
Dagang Avatar asked Aug 04 '11 08:08

Dagang


1 Answers

Pipe your file through following command:

sed 's/.*\(server_log_[0-9]\+\.log\).*/\1/'
like image 130
Paweł Nadolski Avatar answered Sep 21 '22 12:09

Paweł Nadolski