natxo has asked for the wisdom of the Perl Monks concerning the following question:
How could I get the date fields (2017/04/20 10:50:24)? Right now I have this:$ perl -ne '$l=$_ if /received/; END{print $l}' /var/log/rsync.log 2017/04/20 10:50:24 [26050] sent 25 bytes received 326 bytes total s +ize 52165551
Which should at least get me '2017/04/20' (just starting with the regex), but I get nothing back in $date, just the original line. Is it possible to achieve in a oneliner, or do I need to write a proper script? TIA.perl -ne '$l=$_ if /received/; END{print $l}; ($date) = $1 =~ m/^(\d+ +\/\d+\/\/d+) .*/g ; print $date, " \n" ' /var/log/rsync.log
EDIT: Thanks a lot for your solutions. The autosplit switch is really handy.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: oneliner question -- oneliner
by Discipulus (Canon) on Apr 20, 2017 at 09:19 UTC | |
|
Re: one liner question
by Eily (Monsignor) on Apr 20, 2017 at 09:20 UTC | |
|
Re: one liner question
by haukex (Archbishop) on Apr 20, 2017 at 09:51 UTC | |
|
Re: one liner question
by Anonymous Monk on Apr 20, 2017 at 17:37 UTC | |
by natxo (Scribe) on Apr 21, 2017 at 20:44 UTC | |
|
Re: one liner question
by Lotus1 (Vicar) on Apr 21, 2017 at 14:01 UTC | |
by haukex (Archbishop) on Apr 21, 2017 at 15:01 UTC |