My input file is like this:
IDno="1"
Name=Jack
Type=Student
IDno="2"
Name=Jill
Type=Teacher
I am using sed to extract all the IDno and the type only when type is student.
sed -e '/IDno=/b' -e '/Type=Student/b' d
This gets me all lines with type student but not the IDnos.
I want to get
IDno="1"
Type=Student
IDno="2"
but I am getting
Type=Student
What am I doing wrong?
Best Answer
egrep
can get multiple lines from a file. Using a pipe|
as a separator you can pull as many different criteria as you want.egrep
is the equivalent ofgrep -E
.egrep
is a script found in the/bin
folder with the contents pointing toexec grep -E "$@"
.Example:
or
Should output:
Hope this helps!