Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: OffTopic : sed : Alternate (2,4,6..) replacement
It will replace colons with blank and display "$A:that Junk" on
even number of iterations.
which is used to evaluate the if condition.
On 12/16/2003 11:04:31 AM, Stephen.Lee_at_DTAG.Com wrote:
>
> Will this work?
>
> ------------------------------------------------------
> #!/usr/bin/ksh
> THINGY=0
> cat swt | sed 's/:/ /' | while read A B JUNK; do
>
> if [ $THINGY -eq 1 ]; then
> B="that"
> THINGY=0
> else
> THINGY=1
> fi
> echo "$A:$B $JUNK"
>
> done
> ------------------------------------------------------
>
> You can set up a similar loop in awk too.
> The sed 's/:/ /' changes the colon to a space so that the read A B JUNK will
> work.
>
> > -----Original Message-----
> >
> > Hi List
> > I need some help on this;
> > How do i replace the 2nd,4th,6th occurances of a column
> > (vertical) in a
> > file.
> > I know sed does it within a row
> >
> > $ cat swt
> > 01:this is a file1 this
> > 02:this is a file1 this
> > 03:this is line3
> > 04:this is line4
> >
> > $ sed 's/this/that/2' swt
> > 01:this is a file1 that
> > 02:this is a file1 that
> > 03:this is line3
> > 04:this is line4
> > $ sed 's/this/that/1' swt
> > 01:that is a file1 this
> > 02:that is a file1 this
> > 03:that is line3
> > 04:that is line4
> >
> > But i want
> > 01:this is a file1 this
> > 02:that is a file1 this
> > 03:this is line3
> > 04:that is line4
> >
> > I tried awk but awk seems to be going one line at a time.
> >
> > Thanks in Advance.
> >
> > GovindanK
> >
> > --
> > http://www.fastmail.fm - The professional email service
> > --
> > Please see the official ORACLE-L FAQ: http://www.orafaq.net
> > --
> > Author: GovindanK
> > INET: gkatteri_at_fastmail.fm
> >
> > Fat City Network Services -- 858-538-5051 http://www.fatcity.com
> > San Diego, California -- Mailing list and web hosting services
> > ---------------------------------------------------------------------
> > To REMOVE yourself from this mailing list, send an E-Mail message
> > to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> > the message BODY, include a line containing: UNSUB ORACLE-L
> > (or the name of mailing list you want to be removed from). You may
> > also send the HELP command for other information (like subscribing).
> >
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> --
> Author: <Stephen.Lee_at_DTAG.Com
> INET: Stephen.Lee_at_DTAG.Com
>
> Fat City Network Services -- 858-538-5051 http://www.fatcity.com
> San Diego, California -- Mailing list and web hosting services
> ---------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
>
Mladen Gogala
Oracle DBA
-- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Mladen Gogala INET: mladen_at_wangtrading.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Tue Dec 16 2003 - 10:29:26 CST