w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Unix script to recursively search a directory and sub directories to grep and print content between 2 patterns in file

This might work for you:

find . 
     -type f 
     -exec awk 'BEGING {print FILENAME ":"} /Pattern1/ { p=1 ; next }
/Pattern2/ {p=0} p==1 {print $0} END {print ""}' {} ;

Note, this prints the FILENAME, even if Pattern1 was not found!





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.