Re: sed question

From: Hunter, Mark (Mark.Hunter@ANHEUSER-BUSCH.COM)
Date: Thu Jul 10 2003 - 16:12:40 EDT


Replace the ....... with \(.\{250\}.\{250\}.\{250\}.\{194\}
So it becomes:

sed -e '1s/\(.\{250\}.\{250\}.\{250\}.\{194\}\)......\(.*$\)/\1GORDON\2/' <
input > output

The .\{250\} matches exactly 250 characters in a row. Max is 256, so you have
to chunk it.

Mark Hunter

-----Original Message-----
From: Bill Thompson [mailto:bill.thompson@GOODYEAR.COM]
Sent: Thursday, July 10, 2003 2:25 PM
To: aix-l@Princeton.EDU
Subject: Re: sed question

Okay John, since nobody else posted an answer to this, I'll give you method
that uses sed. It works, but it's really ugly. Hopefully this will spark an
idea for someone else and they'll be able to give you a better answer.

sed -e
'1s/\(..........................................................................
.................................................................................
.................................................................................
.................................................................................
.................................................................................
.................................................................................
.................................................................................
.................................................................................
.................................................................................
.................................................................................
.................................................................................
.......................................................................
\)......\(.*$\)/\1GORDON\2/' <inputfile >outputfile

Let me (try to) explain...

The "1s" (that's the number one followed by a lower case "S") at the
beginning sed expression tells sed to change line one only.

There are 944 dots between the first pair of escaped parenthesis. This
shoves the first 944 characters into sed buffer #1.

There are six dots after the first right parenthesis. These represent the
six characters (945-950)you want to replace.

The part between the second pair of escaped parenthesis: "\(.*$\)" shoves
characters 951 to end of line into sed buffer #2.

Now, on the other side of the forward slash (/)...

"\1" tells sed to input the contents of buffer #1 here.

"GORDON" is your new string

"\2" tells sed to input the contents of buffer #2 here.

Like I said. Ugly, but it works :-)

Bill Thompson
Sr UNIX Systems Administrator
The Goodyear Tire & Rubber Co.

Contains Confidential and/or Proprietary Information
May Not Be Copied or Disseminated Without Express Consent of The Goodyear
Tire & Rubber Company.

AIX-L Archives: http://marc.theaimsgroup.com/?l=aix-l&r=1&w=2

----- Original Message -----
From: "John Dunn" <john.dunn@SEFAS.CO.UK>
Newsgroups: bit.listserv.aix-l
To: <aix-l@Princeton.EDU>
Sent: Wednesday, July 09, 2003 4:02 AM
Subject: sed question

> I need a shell script that will change characters 945-950 in the first
line
> only of a file to a specified string, i.e "GORDON". I will not know what
> the original value is. Can I do this with sed, if so, how, or do I need
to
> use awk?
> J



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:17:01 EDT