0

I want to find specific pattern in all the files in a directory and copy them to another line

For E.g I want to find LOG_WARNING in one file XYZ and copy them to another file.

LOG_WARNING (abc, xyz,("WARNING:  Error in sending concurrent_ to pdm\n"));

command i have used is :

grep -rin "LOG_WARNING.*" file_name.c > output.txt

but it is not copying till the semicolon, please note that other texts are available in next line. I want to copy till ;(semi-colon)

Allan
  • 12,117
  • 3
  • 27
  • 51
sushant
  • 41
  • 7

1 Answers1

0

grep -rh "LOG_WARNING" * > out.txt

This will match the pattern in all the files inside the directory. Since you mentioned that the texts that are present after the ';' are on the next line, I have provided this command. This will match the pattern and print the entire line, till the ';'.

Else,

try this

grep -roPh 'LOG_WARNING[^;]*;' * > out.txt

sriramsm04
  • 343
  • 1
  • 7
  • 22