Grep lines between start & end pattern even end pattern in next file
5,094
Solution 1
Try:
$ cat file1 file2 | awk '/pattern1/,/pattern2/'
Solution 2
Using sed
Version:
sed -n '/start pattern/,/end pattern/p' file1 file2
For Saving Output To New File
sed -n '/start pattern/,/end pattern/p' file1 file2 > output
Which will create for you new file called output include the desired result.
Related videos on Youtube
Author by
Vivek Nigam
Updated on September 18, 2022Comments
-
Vivek Nigam over 1 year
My data is like:
First_file.txt
Start abcd efgh hijk lmn
Second_File.txt
opq rst uvw xyz END
I want to
grep
all the line between patterns START & END even END pattern in next fileOutput should be like:
abcd efgh hijk lmn opq rst uvw xyz
-
RomanPerekhrest over 6 yearswhat if there's
Start
string inSecond_File.txt
? -
Sundeep over 6 yearsyou need to add what you tried to solve.. anyway, you'll find an answer here (stackoverflow.com/questions/38972736/… - wasn't able to find similar here).. as far as I know, matching across files is default behavior with sed/awk
-
Vivek Nigam over 6 yearsno start string come again until end string found, its our application logs.
-
Murphy over 6 years
-
Vivek Nigam over 6 yearsi try this command but its work for one file :awk '/Pattern1/,/pattern2/' filename
-
αԋɱҽԃ αмєяιcαη over 6 yearsare the
start
pattern is infirst file
only andend
pattern insecond file
only ?