global sed for "/ /" to "/M/"

global sed for "/ /" to "/M/"

Post by Bill Marc » Sun, 29 Jun 1997 04:00:00





Quote:>I have a line of text that looks like this:

> .E 6734 970621 DH0700/HW/DIH1/ / / / / / /

>Notice that there are 6 occurences of "/ /".
>I wish to sed this line (and others like it) to:

> .E 6734 970621 DH0700/HW/DIH1/M/M/M/M/M/M/

>I have tried several different combinations of sed such as:

>  (1) sed 's/\/ \//\/M\//g'
>  (2) sed 's/\057 \057/\057M\057/g'

Try this:
sed 's:/ :/M:g'

--
Bill Marcum    bmarcum at iglou dot com
"I'm looking at PAGES AND PAGES of stuff even the Franklin Mint couldn't
give away for free." -- K. Mennie

 
 
 

global sed for "/ /" to "/M/"

Post by Derek Atki » Sun, 29 Jun 1997 04:00:00


: I have a line of text that looks like this:

:  .E 6734 970621 DH0700/HW/DIH1/ / / / / / /

: Notice that there are 6 occurences of "/ /".
: I wish to sed this line (and others like it) to:

:  .E 6734 970621 DH0700/HW/DIH1/M/M/M/M/M/M/

: I have tried several different combinations of sed such as:

:   (1) sed 's/\/ \//\/M\//g'
:   (2) sed 's/\057 \057/\057M\057/g'

: Yes, I used the -e option on both of the above scenarios also, but the
: best output I received was:

:  .E 6734 970621 DH0700/HW/DIH1/M/ /M/ /M/ /

: Now, I thought that the g suffix was a "global" qualifier for sed,
: meaning sed changed EVERY occurence of string1 to string2.  In this case
: it seemed to perform the change on every OTHER occurence.  Could someone
: please explain my error, and provide the correct command syntax?

try

sed 's,/ /,/M/,g'|sed 's,/ /,/M/,g'

 
 
 

global sed for "/ /" to "/M/"

Post by Al A » Sat, 05 Jul 1997 04:00:00


most sed implementations lack octal
(
the luck exception i know of is sed15, for dos and unix. download it
from simtel:
                http://uiarchive.cso.uiuc.edu/SearchEngines/dos.cgi
)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    for a 1stop sed needs, join seders, the informal sed mailing list.      
    sed is literate.  sed knows 4 R's: read, 'rite, 'rithmetic, recur.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                        sed informal mailing list

        Of half a dozen sed studs known to sedkind, seders has 2   :
                Greg Ubben       +      Carlos J. G. Duarte.
                               -----

                   sed web pages (in 4 countries)

http://www.wollery.demon.co.uk   seders grab bag (seders official web page
                                                              seder  Casper
http://www.math.fu-berlin.de/~guckes/sed/          seder, Herr Guckes
http://www.math.fu-berlin.de/~leitner/sed/          seder, Herr von Leitner
http://www.dbnet.ece.ntua.gr/~george/#seders  seder, engineer, Dr2b Yiorgos
ftp://olivia.inesc.pt/pub/users/cdua/scripts/sed         the great sed stud
ftp://olivia.inesc.pt/pub/users/cdua/scripts/sh   seder Carlos J. G. Duarte
                                ----

             my favourite DOS/UNIX sed15 (with C source)
(easily compilable for UNIX.  has friendly extenstions/relaxations like hex)
 ftp://uiarchive.uiuc.edu/pub/systems/pc/simtelnet/msdos/txtutl/sed15.zip
 ftp://uiarchive.uiuc.edu/pub/systems/pc/simtelnet/msdos/txtutl/sed15x...

Directory: /pub/systems/pc/simtelnet/msdos/txtutl/
Filename    Type Length  Date    Description
===============================================================================
sed15.zip    B    62082  910930  Unix-compatible streaming editor v1.5 TC src
sed15x.zip   B    20300  910930  Unix-compatible streaming editor v1.5 EXE/docs

              sed15.zip has C source, compilable for UNIX.

             Also, check simtel for u-sedit. has nice docs.

                                ----

                O'Reilly sed books http://www.ora.com
1- sed and awk 2nd edition         by   Dale Dougherty  +  Arnold Robbins
        (mostly for awk)
2- mastering regular expressions   by          Jeffrey E. F. Friedl
        (mostly for perl, emacs, awk.  but touches on sed)

                                ----
                   newsgroup alt.comp.editors.batch      
      though seders news group, alt.comp.editors.batch deals with
batch, AI, data warehousing, OLAP, computer security, filters, linguistics,
      awk, perl, unix, computer seminars, CFP, etc (even sed)

           started by a seder, PhD2b, engineer, the hawk
                         Yiorgos Adamopoulos.    

          most newsfeeds do not carry alt.comp.editors.batch
          but everyone can get it via  dejanews (and others)
  you can even follow up, reply to the poster, etc.  dejanews is great.
             (then he sed: not by sed alone ... lives man)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

: : I have a line of text that looks like this:

: :  .E 6734 970621 DH0700/HW/DIH1/ / / / / / /

: : Notice that there are 6 occurences of "/ /".
: : I wish to sed this line (and others like it) to:

: :  .E 6734 970621 DH0700/HW/DIH1/M/M/M/M/M/M/

: : I have tried several different combinations of sed such as:

: :   (1) sed 's/\/ \//\/M\//g'
: :   (2) sed 's/\057 \057/\057M\057/g'

: : Yes, I used the -e option on both of the above scenarios also, but the
: : best output I received was:

: :  .E 6734 970621 DH0700/HW/DIH1/M/ /M/ /M/ /

: : Now, I thought that the g suffix was a "global" qualifier for sed,
: : meaning sed changed EVERY occurence of string1 to string2.  In this case
: : it seemed to perform the change on every OTHER occurence.  Could someone
: : please explain my error, and provide the correct command syntax?

: try

: sed 's,/ /,/M/,g'|sed 's,/ /,/M/,g'

--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, seders moderator                                      sed u soon
               it is not zat we do not see the  s o l u t i o n          
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+