The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
no options nascimento.rp AIX 2 08-20-2006 03:46 PM
options terms5 UNIX for Dummies Questions & Answers 1 01-27-2006 01:50 AM
options with awk mips Shell Programming and Scripting 2 05-15-2004 04:33 AM
cat and wc options Laura01 Shell Programming and Scripting 1 09-09-2002 12:21 AM
cp options milage UNIX for Dummies Questions & Answers 3 07-13-2001 01:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-04-2006
sivasenthil_k sivasenthil_k is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 14
Question sed h and g options

Hi ..

Happy New Year..

If i do a

sed -e '
/BEGIN/,/END/{
h
/xxx/{
g
p
}
}
' temp1

I have two queries in this script

1.Will the block between BEGIN and END be stored in the hold buffer before executing the /xxx/ ..

2.When will /xxx/ be executed ..( Is it after one full block between BEGIN and END is completed ?)

temp1 looks like

BEGIN
sdfdsf
sdfsdf
xxx
END
BEGIN
sdfdsf
sdfsdf
END


Thanks..Siva
  #2 (permalink)  
Old 01-04-2006
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Have you tested it yourself?

Cheers
ZB
  #3 (permalink)  
Old 01-04-2006
sivasenthil_k sivasenthil_k is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 14
sed h and g options

Yes I tested it myself ..

My objective is to take the block which has only xxx in it

But it gives output like

BEGIN
sdfdsf
sdfsdf
xxx
xxx
END
BEGIN
sdfdsf
sdfsdf
END

.. I am pretty new to sed .. may be my script has some basic error .. please help
  #4 (permalink)  
Old 01-04-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
This looks fine.. It makes use sed's advanced flow control commands

Code:
[/tmp]$ cat 1
BEGIN
sdfdsf
sdfsdf
xxx
END
BEGIN
sdfdsf
sdfsdf
END
[/tmp]$ sed -n -e '/BEGIN/{
:top
N
/END/b end
b top
:end
s_.*xxx.*_&_p
}' 1
BEGIN
sdfdsf
sdfsdf
xxx
END
[/tmp]$
Yet another similiar sed solution
Code:
sed -n -e '/BEGIN/{
:top
/END/!{
N;        
b top
}    
s_.*xxx.*_&_p
}' 1
Cheers'
Vino

Last edited by vino; 01-18-2006 at 04:39 AM..
  #5 (permalink)  
Old 01-04-2006
sivasenthil_k sivasenthil_k is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 14
Smile

Thanks Vino

It works ..

But what if I need the block with two patterns in it ..( the order of occurence of the pattern is not known ..

Could you help me do this using hold and get options in sed ..
I am a beginner in sed and I would love to learn using h and g options ..
( as I had asked in my original question .. /BEGIN,/END/h .. will the block be stored in hold space ??)

Thanks
Siva
  #6 (permalink)  
Old 01-04-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by sivasenthil_k
But what if I need the block with two patterns in it ..( the order of occurence of the pattern is not known ..
Give me an example.

Quote:
Originally Posted by sivasenthil_k
( as I had asked in my original question .. /BEGIN,/END/h .. will the block be stored in hold space ??)
Sed works as follows: Pick up a line. Do the specified operations on that. Read the next line. Do the specified operations... etc.. So, in your case, the first line with /BEGIN/ will be in the hold space.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0