The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Spliting file based on condition Raamc Shell Programming and Scripting 2 05-15-2008 08:51 AM
How to parse through a file and based on condition form another output file sivasu.india UNIX for Advanced & Expert Users 6 02-28-2008 12:59 AM
Moving file to directory based on condition. ramanagh Shell Programming and Scripting 2 02-02-2008 07:41 AM
Splitting a file based on some condition and naming them srivsn Shell Programming and Scripting 1 12-07-2005 07:27 AM
awk script to split a file based on the condition superprogrammer Shell Programming and Scripting 12 06-14-2005 12:59 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2007
Registered User
 

Join Date: Sep 2006
Posts: 75
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-31-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,334
grep "^B" < data
Reply With Quote
  #3 (permalink)  
Old 01-31-2007
Registered User
 

Join Date: Sep 2006
Posts: 75
thanks a lot
Reply With Quote
  #4 (permalink)  
Old 01-31-2007
Registered User
 

Join Date: Jan 2007
Posts: 2
It will work even with out ^
Reply With Quote
  #5 (permalink)  
Old 01-31-2007
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 513
Quote:
Originally Posted by gopinathsekar
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.
Reply With Quote
  #6 (permalink)  
Old 01-31-2007
Registered User
 

Join Date: Jan 2007
Posts: 2
Quote:
Originally Posted by tayyabq8
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..........
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0