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 01:00 AM
Finding a specific pattern from thousands of files ???? aarora_98 Shell Programming and Scripting 6 02-17-2006 05:28 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 03-06-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
Vino,

i think I was wrong in quoting my question. Actually I want the pattern between the pair "OBJECT" and "FILEDS"(excluding the line "FIELDS")

Quote:
$ uname -a
SunOS snvi003 5.8 Generic_117350-20 sun4u sparc SUNW,Sun-Fire-V240
$

I found following awk command working as per my requirements. How can I remove the use of grep here.

$awk '/OBJECT *TYPE/,/FIELDS/' test.dat|grep -v FIELDS
Reply With Quote
Forum Sponsor
  #9  
Old 03-06-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,695
Quote:
Originally Posted by shriashishpatil
Vino,
i think I was wrong in quoting my question. Actually I want the pattern between the pair "OBJECT" and "FILEDS"(excluding the line "FIELDS")
I dont what you the idea that FIELDS was getting printed.

Code:
[/tmp]$ cat txt
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
[/tmp]$ sed -n -e "/OBJECT TYPE/p" -e "/UNIQUE_FIELD/p" txt
OBJECT TYPE="locale", 
NAME=locale_nl_NL, UNIQUE_FIELD=win32_lcid
OBJECT TYPE="locale", NAME=locale_nl_BE
UNIQUE_FIELD=win32_lcid
[/tmp]$
Reply With Quote
  #10  
Old 03-06-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
Vino ,

your command is printing the lines containg "OBJECT TYPE" and "UNIQE_FIELD".

I want the o/p between the pairs "OBJECT TYPE" and "FIELDS".
Quote:
How can I remove the use of grep here.

$awk '/OBJECT *TYPE/,/FIELDS/' test.dat|grep -v FIELDS
Reply With Quote
  #11  
Old 03-06-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,695
This is what you posted.

Quote:
Originally Posted by shriashishpatil
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
And this is what the sed command
Code:
sed -n -e "/OBJECT TYPE/p" -e "/UNIQUE_FIELD/p" txt
gave me...

Code:
OBJECT TYPE="locale", 
NAME=locale_nl_NL, UNIQUE_FIELD=win32_lcid
OBJECT TYPE="locale", NAME=locale_nl_BE
UNIQUE_FIELD=win32_lcid
If your question has changed over the last few replies, please post the output you wish to see.
Reply With Quote
  #12  
Old 03-06-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
I am sorry if I was misleading you.
My question is same right from my first post.

Say my input file is

Quote:
OBJECT TYPE ="abc" UNIQUE_FIELD_ONE=win32_lcid
UNIQUE_FIELD_TWO=win32_lcid
NAME=locale_nl_NL
UNIQUE_FIELD=win32_lcid
UNIQUE_FIELD_TWO=win32_lcid
FIELDS

OBJECT TYPE="XYZ"
NAME=locale_en_CA
UNIQUE_FIELD=win32_lcid
UNIQUE_FIELD_TWO=win32_lcid
FIELDS

OBJECT TYPE="PQRS"
-------
-------
---------
FIELDS
My o/p file look like

Quote:
OBJECT TYPE ="abc" UNIQUE_FIELD_ONE=win32_lcid
UNIQUE_FIELD_TWO=win32_lcid
NAME=locale_nl_NL
UNIQUE_FIELD=win32_lcid
UNIQUE_FIELD_TWO=win32_lcid

OBJECT TYPE="XYZ"
NAME=locale_en_CA
UNIQUE_FIELD=win32_lcid
UNIQUE_FIELD_TWO=win32_lcid
Hope my question is clear now.

Quote:
I want the pattern between the pair "OBJECT" and "FILEDS"(excluding the line "FIELDS")
My second question is
Quote:
How can I remove the use of grep here.

$awk '/OBJECT *TYPE/,/FIELDS/' test.dat|grep -v FIELDS
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:43 AM.


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

Content Relevant URLs by vBSEO 3.2.0