Re: [CentOS] sed question

2015-08-25 Thread Gordon Messmer
On 08/25/2015 11:21 AM, Alice Wonder wrote: cat file.txt |\ sed -e s?"foo"?"bar"?g |\ sed -e s?"dirty"?"clean?" |\ > file2.txt I don't understand why you'd quote that way. Though unlikely, you could potentially match a filename in the working directory, and hose the sed command.

Re: [CentOS] sed question

2015-08-25 Thread Alice Wonder
On 08/25/2015 11:02 AM, Gordon Messmer wrote: Additionally, you can avoid using "cat" to make the script more efficient. You'll start fewer processes, and complete more quickly. cat is almost never needed unless you actually need to con"cat"enate multiple files. I sometimes like to use cat

Re: [CentOS] sed question

2015-08-25 Thread Gordon Messmer
On 08/25/2015 10:50 AM, Jerry Geis wrote: cat my_file.txt | sed 's/CANCELID/$CHANGE/' > cancel.txt sed doesn't perform environment variable expansion. That is to say that when you instruct sed to substitute "$CHANGE" for "CANCELID", "$CHANGE" is a literal string that will be substituted. b

Re: [CentOS] sed question

2015-08-25 Thread John R Pierce
On 8/25/2015 10:50 AM, Jerry Geis wrote: --- This is the two line script CHANGE="1234" cat my_file.txt | sed 's/CANCELID/$CHANGE/' > cancel.txt --- and the my_file.txt has: CANCELID it gets changed to $CHANGE instead of the actual value 1234 . I tried

Re: [CentOS] sed question

2015-08-25 Thread James A. Peltier
- Original Message - | I am trying to use sed to change a value in a pipe. | | --- This is the two line script | CHANGE="1234" | | cat my_file.txt | sed 's/CANCELID/$CHANGE/' > cancel.txt | --- | | and the my_file.txt has: | CANCELID | | it gets

Re: [CentOS] sed question

2015-08-25 Thread Larry Martell
On Tue, Aug 25, 2015 at 1:50 PM, Jerry Geis wrote: > I am trying to use sed to change a value in a pipe. > > --- This is the two line script > CHANGE="1234" > > cat my_file.txt | sed 's/CANCELID/$CHANGE/' > cancel.txt > --- > > and the my_file.txt has: > CA

[CentOS] sed question

2015-08-25 Thread Jerry Geis
I am trying to use sed to change a value in a pipe. --- This is the two line script CHANGE="1234" cat my_file.txt | sed 's/CANCELID/$CHANGE/' > cancel.txt --- and the my_file.txt has: CANCELID it gets changed to $CHANGE instead of the actual value 1234 .

Re: [CentOS] sed with several lines, how?

2010-11-27 Thread Christopher Chan
Hahahaha, I see that you posted this in quite a few places. Let me repeat it here then. BTW, do a bit of homework if you do need fine tuning before posting back on this list. awk 'BEGIN {sawpattern=0} "^[[:alpha:]], ^[[:alpha:]]" {if (($0 ~/[[:alpha:]]/ )&& (sawpattern == 0)) {sawpattern=1}

Re: [CentOS] sed with several lines, how?

2010-11-27 Thread Arthur Bela
thank you, and sorry, if i had formulated wrong, but the "SOMETEXT#X" is a random STRING, like: $ cat testfile.txt alsjflsajfkljasdf asfklasjlkyxcvo kldfjlkasjdfasdf kasfjxcvklajdflas yxcvkjasafjads asdfjkldjlasj uiyxzckjhasfsd $ $ awk 'BEGIN {sawpattern=0} "^SOMETEXT, ^SOMETEXT" {if (($0 ~/S

[CentOS] sed with several lines, how?

2010-11-27 Thread Arthur Bela
hyphen's [ - ] are just for marking the start/end of a pattern, but there are _not in_ the pattern! "OUTPUT" is what i want after "seding" the PATTERN#X's so i for e.g.: need the first, and second "magic" sed "FIRSTMAGIC" PATTERN#1 sed "SECONDMAGIC" PATTERN#2 PATTERN#1: -

Re: [CentOS] sed a particular line in file

2010-04-10 Thread Tom Brown
> % cat foo > Hello line 1 > Hello line 2 > Hello line 3 > > # To change just line 2 > % sed '2s/Hello/There/' > Hello line 1 > There line 2 > Hello line 3 > > # To change line 2 and onwards > % sed '2,$s/Hello/There/' > Hello line 1 > There line 2 > There line 3 > > It's that simple :-) > > y

Re: [CentOS] sed a particular line in file

2010-04-09 Thread Stephen Harris
> I thought i could use sed to change a particular line number but i dont see > that in the man page, i am trying to change a value from line number 6 % cat foo Hello line 1 Hello line 2 Hello line 3 # To change just line 2 % sed '2s/Hello/There/' Hello line 1 There line 2 Hello line 3 # To chan

[CentOS] sed a particular line in file

2010-04-09 Thread Tom Brown
I need to change a value in a file, but this line occurs more than once in this file therefore as i know the line number this value appears on how can i change that? I thought i could use sed to change a particular line number but i dont see that in the man page, i am trying to change a value from

Re: [CentOS] sed help

2010-03-09 Thread Dan Burkland
> -Original Message- > From: centos-boun...@centos.org [mailto:centos-boun...@centos.org] On > Behalf Of Paul Heinlein > Sent: Tuesday, March 09, 2010 11:08 AM > To: CentOS mailing list > Subject: Re: [CentOS] sed help > > On Tue, 9 Mar 2010, chloe K wrote: >

Re: [CentOS] sed help

2010-03-09 Thread Paul Heinlein
On Tue, 9 Mar 2010, chloe K wrote: > Hi > > Can I know how to use sed to substitue 2 instead of 1 at the same time? > > eg: > > sed 's/pchloe.com/abc.com/ ; /192.92.123.5/10.10.0.3/g' orgfile >> newfile sed \ -e 's/pchloe\.com/abc.com/g' \ -e 's/192\.92\.123\.5/10.10.0.3/g' \ orgfile >>

[CentOS] sed help

2010-03-09 Thread chloe K
Hi Can I know how to use sed to substitue 2 instead of 1 at the same time? eg: sed 's/pchloe.com/abc.com/ ; /192.92.123.5/10.10.0.3/g' orgfile >> newfile thank you __ Be smarter than spam. See how smart SpamGuard is at givi

Re: [CentOS] sed (or other) magic to get RPM base names ?

2009-09-21 Thread Christoph Maser
Am Montag, den 21.09.2009, 15:06 +0200 schrieb Alan McKay: > Hey folks, > > Once upon a time I saw some sed magic to take the output of "rpm -qa" > and strip away all the version info to give just the RPM base names. > > And of course I forgot to note it :-/ And have not been able to > replicate

Re: [CentOS] sed (or other) magic to get RPM base names ?

2009-09-21 Thread Ralph Angenendt
On Mon, Sep 21, 2009 at 3:06 PM, Alan McKay wrote: > avahi-0.6.16-1.el5 > avahi-glib-0.6.16-1.el5 > > produce this : > > avahi > avahi-glib r...@knodd:~# rpm -qa --queryformat "%{name}\n" avahi\* avahi avahi-compat-libdns_sd avahi-glib r...@knodd:~# Ralph

[CentOS] sed (or other) magic to get RPM base names ?

2009-09-21 Thread Alan McKay
Hey folks, Once upon a time I saw some sed magic to take the output of "rpm -qa" and strip away all the version info to give just the RPM base names. And of course I forgot to note it :-/ And have not been able to replicate it myself. e.g. from this : avahi-0.6.16-1.el5 avahi-glib-0.6.16-1.el

Re: [CentOS] sed append question

2009-08-19 Thread Filipe Brandenburger
Hi, On Wed, Aug 19, 2009 at 16:20, Joseph L. Casale wrote: > '/string/a \\tstuff\t\t\tmorestuff' != "/string/a \\tstuff\t\t\tmorestuff" Yes, indeed... The rules of quoting and backslashes in the shell are not very uniform and can get quite tricky... Also, the \t is interpreted by sed, and AFAIK i

Re: [CentOS] sed append question

2009-08-19 Thread Joseph L. Casale
>The "a" command expects to be followed by a "\", so it's eating the >one in your first "\t". If you add another "\" it seems to work as you >want it to: > >$ echo string | sed '/string/a \\tstuff\t\t\tmorestuff' >string >stuff morestuff >$ Ah ffs, lol... It would also he

Re: [CentOS] sed append question

2009-08-19 Thread Filipe Brandenburger
Hi, On Wed, Aug 19, 2009 at 13:24, Joseph L. Casale wrote: > Hey guys, > I am trying to make sed append every line containing a string with another > line. > problem is the appended line needs to start with a tab: > # sed -i '/string/a \tstuff\t\t\tmorestuff' file > Obviously \t or \x09 etc doesn

[CentOS] sed append question

2009-08-19 Thread Joseph L. Casale
Hey guys, I am trying to make sed append every line containing a string with another line. problem is the appended line needs to start with a tab: # sed -i '/string/a \tstuff\t\t\tmorestuff' file Obviously \t or \x09 etc doesn't get interpreted unless there are other characters before it? How can

Re: [CentOS] sed

2008-05-23 Thread Les Mikesell
Stephen Harris wrote: On Fri, May 23, 2008 at 06:59:24PM +0200, Thomas Johansson wrote: Stephen Harris wrote: sed 's/^\([^]*[ ]*[^]*\)\([ ]*.*\)$/\1.contoso.com\2/' (where there's a space *and* a TAB inside each of the [ ] ) The above version easier to read and "copy paste

Re: [CentOS] sed

2008-05-23 Thread MHR
On Fri, May 23, 2008 at 8:50 AM, Matt Shields <[EMAIL PROTECTED]> wrote: > > I'd use awk. Put the lines in a file, then do this > > cat test.txt | awk '{ print $1 "\t" $2 ".centos.com\t" $3 "\t" $4 }' > Or just awk '{ print $1 "\t" $2 ".centos.com\t" $3 "\t" $4 }' test.txt > newhostsfile (The ca

Re: [CentOS] sed

2008-05-23 Thread Stephen Harris
On Fri, May 23, 2008 at 06:59:24PM +0200, Thomas Johansson wrote: > Stephen Harris wrote: > > sed 's/^\([^]*[ ]*[^]*\)\([ ]*.*\)$/\1.contoso.com\2/' > > > >(where there's a space *and* a TAB inside each of the [ ] ) > > > The above version easier to read and "copy paste". Space

Re: [CentOS] sed

2008-05-23 Thread Thomas Johansson
Stephen Harris wrote: On Fri, May 23, 2008 at 06:02:29PM +0200, Mihai T. Lazarescu wrote: On Fri, May 23, 2008 at 08:41:19AM -0700, Scott McClanahan wrote: 1.1.1.1foo 10.10.10.10bar bar2 100.100.100.100foobar foobar2 foobar3 == After == 1.1.1.1

Re: [CentOS] sed

2008-05-23 Thread Stephen Harris
On Fri, May 23, 2008 at 06:02:29PM +0200, Mihai T. Lazarescu wrote: > On Fri, May 23, 2008 at 08:41:19AM -0700, Scott McClanahan wrote: > > 1.1.1.1foo > > 10.10.10.10bar bar2 > > 100.100.100.100foobar foobar2 foobar3 > > == After == > > 1.1.1.1foo.contoso.com > > 10.10.10.10ba

Re: [CentOS] sed

2008-05-23 Thread Mihai T. Lazarescu
On Fri, May 23, 2008 at 08:41:19AM -0700, Scott McClanahan wrote: > Not specific to CentOS but I know you guys would be really helpful anyhow. > Basically, I have a file which has been editted in the past very similarly to > the hosts file only now I want to use it as a hosts file and need to run

Re: [CentOS] sed

2008-05-23 Thread Matt Shields
On Fri, May 23, 2008 at 11:41 AM, Scott McClanahan <[EMAIL PROTECTED]> wrote: > Not specific to CentOS but I know you guys would be really helpful anyhow. > Basically, I have a file which has been editted in the past very similarly > to the hosts file only now I want to use it as a hosts file and n

[CentOS] sed

2008-05-23 Thread Scott McClanahan
Not specific to CentOS but I know you guys would be really helpful anyhow. Basically, I have a file which has been editted in the past very similarly to the hosts file only now I want to use it as a hosts file and need to run some fancy sed to massage the data into shape. Currently, the data in th