The original question seems to ask "to extract all the IDno and the type only when type is student." But the example output returns all IDno= lines, so that's rather contradictory...
Here's an answer that only returns the IDno's and Type's when the Type=Student.
sed -n 'N;N;/IDno=.*Type=Student/p' filename | grep -v "^Name="
A little explanation:
-n, --quiet, --silent
suppress automatic printing of pattern space
N;N;
Read/append the next line of input into the pattern space. (twice)
/IDno=.*Type=Student/p
find & print from IDno= to Type=Student
| grep -v "^Name="
don't show the Name= line
I don't like the sed|grep, but not too sure how to get sed to re-search it's output, and a pipe generally says "take this output and do something"... Could do grep|sed too
grep -v "^Name=" t | sed -n 'N;N;/IDno=.*Type=Student/p'
egrep
be easier?egrep -e "IDno=|Type=Student" inputfile
-e d
(not justd
)? otherwise the command is malformed I think. Regardless, it would be more idiomatic to invert the logic using!
rather than by branching past thed
i.e.sed '/IDno=\|Type=Student/!d'