Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    command for replacing text?

    is there a way to replace text strings in a file from the command line (no scripts or programming)?

    I want to replace this line in /etc/inittab

    (replace 5 with 3)

    im making a test and trying to make setup into a single multipart command. what would the command line be?


  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Seattle, WA, USA
    The sed utility can do pattern matching and replacement. So for your particular example:
    sed -e 's/id:5:initdefault/id:3:initdefault/' /etc/inittab
    This would print the modified file to the terminal. You could redirect that into a temp file and replace the original with it. Or you could use the '-i' option to backup the existing copy and automatically make the change. Check the man page for more details.

    sed uses a technique called regular expressions to match patterns in the file. You can do very powerful things with it: find an online resource on regular expressions for more info.

  3. #3

    Thumbs up

    thank you, worked perfectly.


Posting Permissions

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