0

I try to parse log files - get some values from strings and write it into file

First, I get the list of files sorted by mtime.

find . -name log* -printf '%Tm%Tm%Td%TH%TM%TS %p\n'| sort | awk '{print $2}'

it works correctly and prints list of files

For example

./2015195/log/log.08
./2015486/log/log.10
./2015418/log/log.13
./2015415/log/log.14
./2015015/log/log.18
./2015715/log/log.19
./2015115/log/2015-09-10/log.21
...

Next, pass through this list and print words from lines with specific pattern

grep 'pattern' $(find . -name log* -printf '%Tm%Tm%Td%TH%TM%TS %p\n'| sort | awk '{print $2}') | awk '{print $1" "$4}' > prsd.txt

It works but it adds file name to every output line like

./2015195/log/log.08:02:01:09,811 12345ABCD
./2015195/log/log.08:02:02:01:09,975 12345CDEF
./2015195/log/log.08:12:02:02:01:09,978 12345EFGF
./2015195/log/log.08:02:02:01:10,223 12345LJIG
./2015195/log/log.08:02:01:10,275 12345IIUY
...

Here the problem, how to delete those additions?

thanks in advance.

Errainrg
  • 3
  • 2
  • So you don't want `grep` to show the filenames? You are probably referring to [grep without showing path/file:line](http://stackoverflow.com/a/19406829/1983854). – fedorqui Apr 19 '16 at 05:54
  • You might consider using `cut` instead of `awk` for trivial field selection. I would recommend using `find whatever | xargs grep pattern` instead of variable substitution, since that avoids the problem of too long argument lists. – Michael Vehrs Apr 19 '16 at 06:19

1 Answers1

1

From man grep,

   -h, --no-filename
          Suppress the prefixing of file names on output. This is the 
          default when there is only one file (or only standard input)
          to search.
ronakg
  • 4,038
  • 21
  • 46
  • http://askubuntu.com/questions/247290/grep-something-anyfiles-log-afile-csv-dont-need-to-print-the-input-path-a/247380 – kay27 Apr 18 '16 at 22:20