Find the answer to your Linux question:
Results 1 to 4 of 4
Sed is like really old, but for some reason, the sed version on one of the boxes I work with, doesn't support inplace editing. this is annoying because you then ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    26

    inplace editing (-i) in Sed

    Sed is like really old, but for some reason, the sed version on one of the boxes I work with, doesn't support inplace editing. this is annoying because you then generate a new file every time you run it through sed.

    I guess you can't specify more than one "find and replace" per sed command, can you? Or there's no trick to it?

    I'm not sure I should go and upgrade the version of sed on there in case it breaks something... any ideas?

    *edit* I just found replace, but as I want to replace a load of ^Ms with nothing, it won't work :/

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Quote Originally Posted by Azrael2
    the sed version on one of the boxes I work with
    What OS / version?

    Quote Originally Posted by Azrael2
    I guess you can't specify more than one "find and replace" per sed command, can you?
    Yes you can; see the -e option.

    Quote Originally Posted by Azrael2
    I want to replace a load of ^Ms with nothing
    One option:
    awk '{ sub("\r$", ""); print; }' your_file_here > new_file_here

    Another option:
    dos2unix your_file_here

    Another option:
    Search the forums. This has been discussed before.

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    26
    The best way I found is perl -pi -e and then the same syntax you would use for Sed. Works a treat, and is much tidier. thanks anyway

  4. #4
    Linux Enthusiast
    Join Date
    Apr 2004
    Location
    UK
    Posts
    658
    There is a program called sponge, which lets you do things like:

    Code:
    sed 'pattern' /file | sponge /file
    without clobbering /file.

    Chris...
    To be good, you must first be bad. "Newbie" is a rank, not a slight.

Posting Permissions

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