Re: sed awk question

From: David J. Weller-Fahy <dave-lists-aklug@weller-fahy.com>
Date: Sat Jun 12 2004 - 01:24:56 AKDT

* Arthur Corliss <acorliss@nevaeh-linux.org> [2004-06-11 19:55 -0800]:
> > * DENNIS BYRNE <asdcb1@uaa.alaska.edu> [2004-06-11 17:41 -0800]:
> > > let's say I have a file.
> > > BOFa\nb'pattern'd\ne'pattern'y\nzEOF
> > >
> > > I want to spilt this file at 'pattern', using something like :
> > > cat filename | sed s/'pattern'/EOF/
> > > [snip]
> > >
> > > suggestions?
> >
> > Maybe try the command 'split' (man 1 split)?
> >
>
> The problem with split is that it won't handle splitting via a regex,
> it would only help if the pattern is predictably at specific
> locations. And then you'd have to do a round of sed on each file to
> remove the pattern from the split files after that.

Yep. I assumed that he wanted to split the file, and didn't know about
the split command. Didn't think he might want to do it with sed/awk
specifically. I believe he ended up using csplit (never used it).

> Here's a one-liner that will do it, which assumes your file is "test",
> the pattern to replace is "foobar":
>
> [snip]

* Arthur Corliss <acorliss@nevaeh-linux.org> [2004-06-11 19:59 -0800]:
> On Fri, 11 Jun 2004, Arthur Corliss wrote:
>
> I just realised that you asked for awk/sed examples. Gawk will do the
> job (but not POSIX awk, I believe), but I don't know of a way to make
> sed handle the job off-hand. In this case, Perl is certainly the
> easiest...

Hrm. I believe it'd be doable with sed, and something like the
following may work.

sed 's/\(.*\)pattern\(.*\)pattern\(.*\)/\1\2\3/' inputfile

However, it is late. I'll think more on it tomorrow.

Regards,

-- 
dave [ please don't CC me ]
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Sat Jun 12 01:20:26 2004

This archive was generated by hypermail 2.1.8 : Sat Jun 12 2004 - 01:20:29 AKDT