Results 1 to 3 of 3

Thread: [opensuse 12.2 mantis] sed command -- how to

  1. #1
    Join Date
    May 2009
    Location
    Liège Walifornia
    Posts
    490

    Default [opensuse 12.2 mantis] sed command -- how to

    Greetings !!

    I'm searching a way to delete all the spaces (0x20 '\ ' caracters) from a file named map3.cssm.

    It works with sed 's/\ //g' map12x12/map3.cssm > map12x12/map003.cssm but I wanted to redirect the result displayed by sed to the file itself.

    sed 's/\ //g' map12x12/map3.cssm > map12x12/map3.cssm resulted to an emply file
    sed 's/\ //g' map12x12/map3.cssm >> map12x12/map3.cssm resulted to a double content !

    Code:
    220000000010
    000022000000
    200000000100
    200030000000
    000030001000
    200300000050
    000000010050
    000030000050
    004030100050
    004030333050
    004000000000
    004004444000
    220000000010
    000022000000
    200000000100
    200030000000
    000030001000
    200300000050
    000000010050
    000030000050
    004030100050
    004030333050
    004000000000
    004004444000
    How can I save the "seded" result to the file itself ?
    And it there a way to apply this sed with a wildcard ?

    sed 's/\ //g' map12x12/map*.cssm

    Thanx in advance !!

  2. #2

    Default AW: [opensuse 12.2 mantis] sed command -- how to

    Quote Originally Posted by soundlord View Post
    How can I save the "seded" result to the file itself ?
    See "man sed":
    Code:
           -i[SUFFIX], --in-place[=SUFFIX]
    
    
    
                  edit files in place (makes backup if SUFFIX supplied)
    And it there a way to apply this sed with a wildcard ?
    Yes. Just use a wildcard in the filename. Or you can also specify more than one file.

    And you can always use a "for" loop of course.

  3. #3

    Default Re: [opensuse 12.2 mantis] sed command -- how to

    Quote Originally Posted by soundlord View Post
    Greetings !!

    I'm searching a way to delete all the spaces (0x20 '\ ' caracters) from a file named map3.cssm.

    It works with sed 's/\ //g' map12x12/map3.cssm > map12x12/map003.cssm but I wanted to redirect the result displayed by sed to the file itself.

    sed 's/\ //g' map12x12/map3.cssm > map12x12/map3.cssm resulted to an emply file
    sed 's/\ //g' map12x12/map3.cssm >> map12x12/map3.cssm resulted to a double content !

    Code:
    220000000010
    000022000000
    200000000100
    200030000000
    000030001000
    200300000050
    000000010050
    000030000050
    004030100050
    004030333050
    004000000000
    004004444000
    220000000010
    000022000000
    200000000100
    200030000000
    000030001000
    200300000050
    000000010050
    000030000050
    004030100050
    004030333050
    004000000000
    004004444000
    How can I save the "seded" result to the file itself ?
    And it there a way to apply this sed with a wildcard ?

    sed 's/\ //g' map12x12/map*.cssm

    Thanx in advance !!
    GNU sed(1) has the i flag/option which is just like.

    Code:
    sed 's/\ //g' map12x12/map3.cssm > tmpfile && mv tmpfile  map12x12/map3.cssm
    Which redirect to a tempfile and move back to the original file. So some folks would insist that sed is not a file editor because if the original file has a symlink then it might broke. Also a fifo is a secure way of making tempfiles e.g. not colliding with thesame file name within your local files.
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •