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
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
Need help to parse the file navsharan Shell Programming and Scripting 3 01-17-2008 11:58 AM
Parse XML file viki Shell Programming and Scripting 5 04-13-2007 01:25 AM
How to parse a XML file using PERL and XML::DOm girigopal Shell Programming and Scripting 0 06-27-2005 03:46 AM
using getopt to parse a file coolguyshail Shell Programming and Scripting 1 06-08-2005 03:58 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-27-2007
Registered User
 

Join Date: Sep 2006
Posts: 75
Stumble this Post!
Parse file

Hi Friends,

I have a file in the format shown (Name followed by address
I need only the address part please see the output.
I have tried using nawk but I am not getting the desired output.



SAM
ADDRS 64874 FRANKLYN DR
IRVINE TX - 74394;
538 FRED ASSOCIATES
PETER
ADDRS 84734 PANTHER CREEK
OWENSMOUTH MI - 88347;
3643 HARRIS

**********************output

ADDRS 64874 FRANKLYN DR
IRVINE TX - 74394;
ADDRS 84734 PANTHER CREEK
OWENSMOUTH MI - 88347;


************

nawk 'BEGIN{RS="" ; FS = "\n"}
{
flag=0;
for( i = 1;i <= NF; ++i )
{
if (match ($i , "^ADDRS" ))
{ flag=1; break; }
}

if (flag == 1) print
}' a

******************************
Thanks a Lot in advance

S
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-27-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
Code:
awk '{ if ( $0 ~ "^ADDRS" ) { print; getline tmp; print tmp } }' filename
Reply With Quote
  #3 (permalink)  
Old 03-27-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
Code:
sed -n "/^ADDRS/{N;p}" file
Reply With Quote
  #4 (permalink)  
Old 03-27-2007
Registered User
 

Join Date: Sep 2006
Posts: 75
Stumble this Post!
I would like to have the output between
"ADDRS" and ";" only
with this input I am not getting the address part.

Can you please help

SAM
ADDRS 64874 FRANKLYN DR
IRVINE TX -
'74394;
538 FRED ASSOCIATES
PETER
ADDRS 84734 PANTHER CREEK
OWENSMOUTH MI - 88347;
3643 HARRIS
Reply With Quote
  #5 (permalink)  
Old 03-27-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
Quote:
Originally Posted by sbasetty
I would like to have the output between
"ADDRS" and ";" only
with this input I am not getting the address part.

Can you please help

SAM
ADDRS 64874 FRANKLYN DR
IRVINE TX -
'74394;
538 FRED ASSOCIATES
PETER
ADDRS 84734 PANTHER CREEK
OWENSMOUTH MI - 88347;
3643 HARRIS
Code:
sed -n "/^ADDRS/,/;/p" file
Reply With Quote
  #6 (permalink)  
Old 03-27-2007
Registered User
 

Join Date: Sep 2006
Posts: 75
Stumble this Post!
Thank you very much guys It worked
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:56 PM.


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