Input:
START
OS:: UNIX
Release: xxx
Version: xxx
END
START
OS:: LINUX
Release: xxx
Version: xxx
END
START
OS:: Windows
Release: xxx
Version: xxx
END
Here i am trying to get all the information between START and END, only if i could match OS Type.
I can get all the data between the range START and END, however i dont know how to match the pattern
Using SED
sed -n '/START/,/END/p'
using AWK
awk '/START/,/END/'
Expected Output while searching for Linux:
START
OS:: LINUX
Release: xxx
Version: xxx
END
need help!!
Thanks in Advance
Hello Dharmaraja,
Welcome to forums, I hope you will enjoy learning/sharing knowledge here. Could you please try following and let me know if this helps you.
awk '/START/{count++} /OS.*LINUX/ && count{count++} /END/ && count==2{print val RS $0;val=count="";next}{val=val?val ORS $0:$0}/END/{count=val=""}' Input_file
Output will be as follows.
START
OS:: LINUX
Release: xxx
Version: xxx
END
EDIT: Adding a non-one liner form of solution too now.
awk '
/START/{
count++
}
/OS.*LINUX/ && count{
count++
}
/END/ && count==2{
print val RS $0;
val=count="";
next
}
{
val=val?val ORS $0:$0
}
/END/{
count=val=""
}
' Input_file
Thanks,
R. Singh
RudiC
3
Try also
awk -vRS="END\n" -vORS="END\n" '/[Ll][Ii][Nn][Uu][Xx]/' file
START
OS:: LINUX
Release: xxx
Version: xxx
END
ctac
4
You can try this one too
sed -n '/START/{N;/LINUX/{:A;N;/END/!bA;p;q}}' infile