Re: Modifying strings in a file.

From: Ron Schwingel (rschwing@NDSLTD.COM)
Date: Thu Aug 29 2002 - 09:27:02 EDT


The solution was to use the following offered by Bruce Zimmer.

        sed '/^#word1 /s/#//'

I would like to thank everyone who responded for your help.

Ron Schwingel
Technical Support

NDS Solutions
303.755.4411(phone)
303.755.4545(fax)
rschwing@ndsltd.com

 -----Original Message-----
From: Bruce Zimmer [mailto:b.r.zimmer@WORLDNET.ATT.NET]
Sent: Thursday, August 29, 2002 6:05 AM
To: aix-l@Princeton.EDU
Subject: Re: Modifying strings in a file.

I think that the way to go with this ( after determining the exact rules
) would be to use a pattern in the address of the line to be changed.
Using an expanded example such as

word1 word3 word2 word4
#word2 word5
word23 word82
#word1 word2 word3 word4

and only line # 4 is desired to be changed.

sed '/^#word1 /s/#//'

   This limits the substitution command to only lines that begin with
#word1 and will leave all other lines containing a # untouched. In
addition to regular expressions addresses can also be distinct numbers
such as '5s/#//'. You can also use ranges of either regular expressions
or numbers or symbols, '/re1/,/re2/s/#/'/, or '5,10s/#//' this would
make the changes on all lines that are contained between re1 and re2
(5,10). If the pair of re's match multiple times in the file, I am not
sure if sed will take the largest range, which would be from the first
occurrence of re1 to the last occurrence of re2, or if it will restrict
application of the command to each smaller range. One additional address
is $ which id the last line of the file. This can be used with either a
regular expression or distinct number, or by itself. '5,$s/#//' would
remove all comments on line 5through the end of the file. The address
range '1,$' is the default address range if none is specified.

HTH

Bruce Zimmer
Central Data Systems
(248) 615-4644 (direct)
(248) 705-9231 (cell)
bzimmer@centraldata.com

-----Original Message-----
From: IBM AIX Discussion List [mailto:aix-l@Princeton.EDU] On Behalf Of
Fabrice Guerini
Sent: Wednesday, August 28, 2002 5:55 PM
To: aix-l@Princeton.EDU
Subject: Re: Modifying strings in a file.

On 01:47 PM 8/28/2002, Ron Schwingel uttered:
>Good. Getting closer. I will not always know how many words in a line.
I
>just used word1 word2 word3 word4 as an example. What can I use if
>I don't know how many white spaces are in a line? Something that
>acts as a wildcard for everything before and after the string I am
>looking for on the line.
>
>Something to replace this I would think.
>
> \([^ ]* [^ ]* [^ ]* [^ ]*\)

OK. So what EXACTLY determines what kind of line must be changed? If you
don't have a clear syntax, you can't do it programmatically.

+===========================================================+
| Fabrice "Script It!" Guerini Blue Martini Software, Inc. |
| Senior Operations Engineer 2600 Campus Drive |
| Tel: (650) 356-7576 San Mateo, CA 94403-2522 |
| Fax: (650) 356-4001 www.bluemartini.com |
+===========================================================+



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:10 EDT