Find the answer to your Linux question:
Results 1 to 3 of 3
Hi there! I've written a simple shell script for moving some files, but before I move one of the .ini files, I would like to replace "userid=12321" with "userid=4565" (for ...
  1. #1
    JK1
    JK1 is offline
    Just Joined!
    Join Date
    Jul 2011
    Posts
    1

    Script to replace text

    Hi there!

    I've written a simple shell script for moving some files, but before I move one of the .ini files, I would like to replace "userid=12321" with "userid=4565" (for instance). If it matters, the ini file contains multiple lines.

    Thanks.

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    Code:
    sed 's/userid=12321/userid=4565/' FILE
    If you want to do the replace in FILE, then add this flag -i
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Aug 2011
    Posts
    3
    As Irithori pointed out, sed is the correct command to do this. The syntax is:

    Code:
    sed 's/Pattern_to_be_replaced/New_Pattern_to_replace/' -i File_Name
    Good luck with your script!

Posting Permissions

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