![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| no options | nascimento.rp | AIX | 2 | 08-20-2006 11:46 AM |
| options | terms5 | UNIX for Dummies Questions & Answers | 1 | 01-26-2006 10:50 PM |
| options with awk | mips | Shell Programming and Scripting | 2 | 05-15-2004 12:33 AM |
| cat and wc options | Laura01 | Shell Programming and Scripting | 1 | 09-08-2002 08:21 PM |
| cp options | milage | UNIX for Dummies Questions & Answers | 3 | 07-12-2001 09:20 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Have you tested it yourself?
Cheers ZB |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
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]$
Code:
sed -n -e '/BEGIN/{
:top
/END/!{
N;
b top
}
s_.*xxx.*_&_p
}' 1
Vino Last edited by vino; 01-18-2006 at 01:39 AM. |
|
#5
|
|||
|
|||
|
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
|
||||
|
||||
|
Quote:
Quote:
|
|
#7
|
|||
|
|||
|
Hi Vino
Thanks for the reply Example is .. Say I need the blocks with xxx and yyy in the file below ( I need the first and last blocks to be in the output .. which has xxx and yyy ) BEGIN aaa yyy bbb ccc xxx END BEGIN aaa yyy bbb ccc END BEGIN aaa xxx bbb ccc END BEGIN aaa xxx bbb ccc yyy END |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|