Code Comments
Programming Forum and web based access to our favorite programming groups.It seems to me that sed & awk are single line based ? I want to delete blocks of text which look like: <opening pattern> <2 to 5 lines> <closing pattern> If I use the <2 to 5 lines>, I can avoid deleting all the good stuff, up to the 'next' <closing pattern> in case the assumed <closing pattern> is missing/undetected. Thanks for any feedback, == Chris Glur.
Post Follow-up to this messageOn Mar 20, 7:55 am, problems@gmail wrote: > It seems to me that sed & awk are single line based ? > > I want to delete blocks of text which look like: > <opening pattern> > <2 to 5 lines> > <closing pattern> > > If I use the <2 to 5 lines>, I can avoid deleting all the good > stuff, up to the 'next' <closing pattern> in case the assumed > <closing pattern> is missing/undetected. > > Thanks for any feedback, > > == Chris Glur. ex is well suited for this kind of edit. ex is the command line part of vi (what you type at the colon). I'm busy right now but if you google ex edit tutorial you should see how to use it.
Post Follow-up to this messageOn Thu, 20 Mar 2008 10:55:05 -0500, problems wrote: > It seems to me that sed & awk are single line based ? > > I want to delete blocks of text which look like: <opening pattern> > <2 to 5 lines> > <closing pattern> > > If I use the <2 to 5 lines>, I can avoid deleting all the good stuff, up > to the 'next' <closing pattern> in case the assumed <closing pattern> is > missing/undetected. > > Thanks for any feedback, > Pseudocode: if line matches opening pattern, set flag if flag is clear, print line if line matches closing pattern, clear flag If you want to keep the two pattern lines, interchange the locations of the two tests. -- T.E.D. (tdavis@mst.edu)
Post Follow-up to this messageOn 2008-03-20, problems@gmail <problems@gmail> wrote: > I want to delete blocks of text which look like: ><opening pattern> ><2 to 5 lines> ><closing pattern> > Thanks for any feedback, Try these for ideas. See the "SELECTIVE DELETION OF CERTAIN LINES:" section. http://www.eng.cam.ac.uk/help/tpl/unix/sed.html nb
Post Follow-up to this messageOn 3/20/2008 10:55 AM, problems@gmail wrote: > It seems to me that sed & awk are single line based ? sed is line-based, awk is record-based. > I want to delete blocks of text which look like: > <opening pattern> > <2 to 5 lines> > <closing pattern> Use: awk -v RS="<closing pattern>" '...' file to use "<closing pattern>" as the record separator. > If I use the <2 to 5 lines>, I can avoid deleting all the good > stuff, up to the 'next' <closing pattern> in case the assumed > <closing pattern> is missing/undetected. Post some sample input and expected output for more help. Ed.
Post Follow-up to this messageawk can definitely understand multi-line patterns. All that you have to do is set the RS (record separator) variable. The best place to do this would be in the BEGIN however you can change this anytime during the execution. The best part is RS can also be a regular expression like RS="</[^>]*>" . <problems@gmail> wrote in message news:1206028330.11645@vasbyt.isdsl.net... > It seems to me that sed & awk are single line based ? > > I want to delete blocks of text which look like: > <opening pattern> > <2 to 5 lines> > <closing pattern> > > If I use the <2 to 5 lines>, I can avoid deleting all the good > stuff, up to the 'next' <closing pattern> in case the assumed > <closing pattern> is missing/undetected. > > Thanks for any feedback, > > == Chris Glur. >
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.