Read file based on condition

Hi Friends,

Can any one help with this:
I have a huge file with the format as
A SAM 4637
B DEPT1 4758 MILAN
A SMITH 46585
B DEPT2 5385 HARRYIS
B SAMUL 63547 GEORGE
B DANIEL 899 BOISE
A FRES 736 74638

I have to read this file and write only the records that starts with "B" only

output should be:
B DEPT1 4758 MILAN
B DEPT2 5385 HARRYIS
B SAMUL 63547 GEORGE
B DANIEL 899 BOISE

Thanks in advance

S :slight_smile:

grep "^B" < data

thanks a lot

It will work even with out ^

No, it won't work, we need to find lines containing a "B" at the start, so we need to mention it, a "^B" tells grep to look for lines having B as their first character, hope you got the concept.

I got it.....Thanks tayyabq8.......... :cool: