-1

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 file

Output should be like:

abcd
efgh
hijk
lmn
opq
rst
uvw
xyz

  • what if there's Start string in Second_File.txt ? – RomanPerekhrest Dec 27 '17 at 11:16
  • you 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 – Sundeep Dec 27 '17 at 11:18
  • no start string come again until end string found, its our application logs. – Vivek Nigam Dec 27 '17 at 11:43
  • idownvotedbecau.se/noattempt – Murphy Dec 27 '17 at 12:11
  • i try this command but its work for one file :awk '/Pattern1/,/pattern2/' filename – Vivek Nigam Dec 27 '17 at 12:50
1

Try:

$ cat file1 file2 | awk '/pattern1/,/pattern2/'
1

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.