[CLUE-Tech] find & replace on a tree of files

Greg Knaddison greg.knaddison at gmail.com
Mon Nov 1 15:30:22 MST 2004


How about one of these beauties shamelessly copied from
http://www.student.northpark.edu/pemente/sed/sed1line.txt

which is a VERY useful file.

Greg


+++
FILE SPACING:

 # double space a file
 sed G

 # double space a file which already has blank lines in it. Output file
 # should contain no more than one blank line between lines of text.
 sed '/^$/d;G'

 # triple space a file
 sed 'G;G'

 # undo double-spacing (assumes even-numbered lines are always blank)
 sed 'n;d'

 # insert a blank line above every line which matches "regex"
 sed '/regex/{x;p;x;}'

 # insert a blank line below every line which matches "regex"
 sed '/regex/G'

 # insert a blank line above and below every line which matches "regex"
 sed '/regex/{x;p;x;G;}'


On Mon,  1 Nov 2004 15:13:43 -0700, David L. Willson
<dlwillson at thegeek.nu> wrote:
> Now, if only I could mod that so that it clears everything but one newline
> between <head> and <title> and everything but one newline between </title> and
> </head>, I'd be a happy dude.  It seems that I cannot find the right set of
> RegEx's to do this...  Help?
> 
> 
> ____________________
>     David L. Willson
>   tel://720.333.LANS
>  Linux+ A+ Net+ MCSE
> 
> Quoting "David L. Willson" <DLWillson at thegeek.nu>:
> 
> > Never let it be said that I missed an opportunity to show publically that I
> > am
> > the slow kid...
> >
> > I just figgered out how to do this thing, and it seemed cool to me, so I'm
> > sending it on to you.
> >
> > The following one-liner is polluted with whacks to show you that it really
> > should be all-on-one-line.  Actually, you can use it all-on-one-line, or with
> > a
> > whack at the end of each sub-line, like you see here.
> >
> > What it does is the sub-tree beginning here (.), looking for files matching
> > the
> > spec '*.hay', which could be any spec.  The one I use most often is, sadly,
> > '*.asp'.  Then, for each matching file, it finds each instance of
> > 'old_needle'
> > and replaces that text with 'new_needle', globally.
> >
> > Incidentally, don't mess with the space-whack-semicolon at the end of the
> > command, it matters a lot.
> >
> > find . \
> >  -iname '*.hay' \
> >  -exec \
> >   sed -e s/old_needle/new_needle/g -i.backup {} \;
> > ____________________
> >     David L. Willson
> >   tel://720.333.LANS
> >  Linux+ A+ Net+ MCSE
> >
> >
> >
> >
> >
> >
> > -------------------------------------------------
> > This mail sent through IMP: http://horde.org/imp/
> > _______________________________________________
> > CLUE-Tech mailing list
> > Post messages to: CLUE-Tech at clue.denver.co.us
> > Unsubscribe or manage your options:
> > http://clue.denver.co.us/mailman/listinfo/clue-tech
> >
> 
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
> _______________________________________________
> CLUE-Tech mailing list
> Post messages to: CLUE-Tech at clue.denver.co.us
> Unsubscribe or manage your options: http://clue.denver.co.us/mailman/listinfo/clue-tech
>



More information about the clue-tech mailing list