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
extract x lines after a pattern - place each result in separate file gobi Shell Programming and Scripting 5 06-06-2008 12:03 PM
extract field of characters after a specific pattern - using UNIX shell script jansat HP-UX 2 05-27-2008 09:08 PM
nawk-how count the number of occurances of a pattern, when don't know the pattern cyber111 Shell Programming and Scripting 2 05-11-2008 12:00 AM
Breaking output for specific pattern shoeb_syed UNIX for Dummies Questions & Answers 2 03-08-2006 12:00 AM
Finding a specific pattern from thousands of files ???? aarora_98 Shell Programming and Scripting 6 02-17-2006 04:28 AM

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

Join Date: Dec 2005
Location: Pune
Posts: 78
Stumble this Post!
to separate a specific pattern

Hi friends,

I have a file with following pattern.

OBJECT TYPE="locale",
NAME=locale_nl_NL, UNIQUE_FIELD=win32_lcid
FIELDS
clarify_lang = 0;
END_FIELDS
END_OBJECT NAME=locale_nl_NL

OBJECT TYPE="locale", NAME=locale_nl_BE
UNIQUE_FIELD=win32_lcid
FIELDS
iso_cntry = "BE";
END_FIELDS
END_OBJECT NAME=locale_nl_BE



I want to saparate lines starting with OBJECT till FIELDS. e.g.
My o/p file should look like

OBJECT TYPE="locale",
NAME=locale_nl_NL, UNIQUE_FIELD=win32_lcid

OBJECT TYPE="locale", NAME=locale_nl_BE
UNIQUE_FIELD=win32_lcid



How this can be done using perl/awk/sed??


thanks in advance,
-Ashish
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-06-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,658
Stumble this Post!
Code:
sed -n -e '/OBJECT TYPE/{N;p}' input.txt
Reply With Quote
  #3 (permalink)  
Old 03-06-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
Stumble this Post!
I found follwing command useful for this.

$awk '/OBJECT *TYPE/,/FIELDS/' test.dat|grep -v FIELDS

any better, neat answers??
Reply With Quote
  #4 (permalink)  
Old 03-06-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
Stumble this Post!
Vino,

seems some syntax problem with sed.

$ sed -n -e '/OBJECT TYPE/{N;p}' test1.dat
sed: command garbled: /OBJECT TYPE/{N;p}
$
Reply With Quote
  #5 (permalink)  
Old 03-06-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,658
Stumble this Post!
Quote:
Originally Posted by shriashishpatil
Vino,

seems some syntax problem with sed.

$ sed -n -e '/OBJECT TYPE/{N;p}' test1.dat
sed: command garbled: /OBJECT TYPE/{N;p}
$
Code:
sed -n -e "/OBJECT TYPE/{N;p}" test1.dat
?
Reply With Quote
  #6 (permalink)  
Old 03-06-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
Stumble this Post!
vino ,
same problem.

Quote:
$ sed -n -e "/OBJECT TYPE/{N;p}" test1.dat
sed: command garbled: /OBJECT TYPE/{N;p}
$
Reply With Quote
  #7 (permalink)  
Old 03-06-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,658
Stumble this Post!
Post the results of uname -a I guess it must be something with your sed.

Try this.
sed -n -e "/OBJECT TYPE/p" -e "/UNIQUE_FIELD/p" input.txt
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:16 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