|
Re: Stingily extracting a block of lines: msg#00020editors.sed.user
Hi, Another possible solution could be as follows: sed -n '{ /bundle/,${ x G s/\n/|/g ${ s/[^[.bundle.]]*\(.*\.elm\).*/\1/g s/|/\ /g p } h } }' 1.txt where 1.txt contains the desired input. regards, Kaushik sed-users@xxxxxxxxxxxxxxx wrote on 12/08/2005 04:46:17 PM: > On Thursday 08 December 2005 02:38, you wrote: > > Entity Angus Leeming spoke thus: > > >> I want to extract a range of lines beginning with the word 'bundle' and > > >> ending with the word '.eml,'. The 'bundle' delimiter will occur > > >> repeatedly throughout the file, so I want to use the most recent > > >> instance (greedy). > > >> > > >> How would I do it using sed? > > > > > > You're being too vague. Guessing that your data looks like > > > > > > the beginning > > > foo > > > foo bundle bar 1 > > > bar > > > baz > > > foo bundle baz 2 > > > noise > > > noise > > > bar .elm > > > noise > > > the end > > > > > > Then the sed script is simply: > > > > > > sed -n '/bundle/,/\.elm/p' input.txt > output.txt > > > > Yes, that is essentially it, but your script returns lines from the first > > instance of bundle, and I want it to return lines starting from the last > > instance in the file. > > Then the solution is a little more involved. Logically, it becomes: > > Step 1. Store all lines from the first "bundle" to ".elm" in the hold space. > Step 2. Move this hold space to the pattern space for further processing. > Step 3. Remove all lines up to the final "bundle". > > Use the sed script below, trial.sed, as > sed -n -f trial.sed input.txt > output.txt > > Regards, > Angus > > /bundle/,/\.elm/{ > # Copy all lines from the first "bundle" to the first ".elm" > # into the hold space. > H > > # On reaching ".elm"... > /\.elm/{ > # Copy the contents of the hold space back into the pattern space. > g > > # If the pattern space contains more than one "bundle" line > # then strip everything up to the beginning of the final > # "bundle" line. > /bundle[^\n]*\n.*bundle/s/^.*\n\([^\n]*bundle\)/\1/ > > # Don't forget to print... > p > } > } > > > > -- > > Yahoo! Groups Links > > > > > > > ForwardSourceID:NT000191A6 Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you [Non-text portions of this message have been removed] ------------------------ Yahoo! Groups Sponsor --------------------~--> Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life. http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/dkFolB/TM --------------------------------------------------------------------~-> -- Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/sed-users/ <*> To unsubscribe from this group, send an email to: sed-users-unsubscribe@xxxxxxxxxxxxxxx <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Stingily extracting a block of lines: 00020, Angus Leeming |
|---|---|
| Next by Date: | Re: Stingily extracting a block of lines: 00020, Angus Leeming |
| Previous by Thread: | Re: Stingily extracting a block of linesi: 00020, Angus Leeming |
| Next by Thread: | Re: Stingily extracting a block of lines: 00020, Angus Leeming |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |