0

I'm using grep to look for a specific string in log-files. It's sometimes a little tricky to see the output refers to the next file already, like:

354058:c1.com/client-01.log:13:30:04 INFO:       Item: created widget in ARRIVALS
360746:c1.com/client-01.log:13:39:46 INFO:          change transfer to contact
379144:c3.com/client-01.log:13:30:02 INFO:       Item: created widget in ARR
392162:c3.com/client-01.log:13:51:59 INFO:       Item: created widget in ARR
367422:c5.com/client-01.log:13:51:56 INFO:       searching for Sign 
367446:c5.com/client-01.log:13:51:59 INFO:       Item: created widget in ARRIVALS
367629:c5.com/client-01.log:13:52:12 INFO:          change from initial to contact
371979:c9.com/client-01.log:14:00:19 INFO:          change workflow to tgl

Is there a way to put a separator after each file?

  • There's nothing like that built into grep. Use a for loop to grep+print separator for each file or, if you know that your file names can not contain colons, post-process the output to insert a separator before each new filename e.g. grep [...] | awk -F':' '!seen[$1]++{printf "%s\n", "DELIMITER"};1' – don_crissti Apr 25 '18 at 14:54
  • You can try grep -0, It's not perfect but you get separator – ctac_ Apr 25 '18 at 19:49
  • @ctac_ - it separates after each line, that's just making things even more confusing – Qohelet Apr 26 '18 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.