Find the answer to your Linux question:
Results 1 to 3 of 3
Is there any way to edit multi text file like: Search/Replace? I can search multi files for a text like in this command: cat $(find /path) | grep "some text1" ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    20

    Can I Edit Multi Files?

    Is there any way to edit multi text file like: Search/Replace?
    I can search multi files for a text like in this command:
    cat $(find /path) | grep "some text1"

    but I can't replace it

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by kdman View Post
    Is there any way to edit multi text file like: Search/Replace?
    I can search multi files for a text like in this command:
    cat $(find /path) | grep "some text1"

    but I can't replace it
    You need sed for that:

    Code:
    find /path | while read file
    do
      sed -i 's/orig_text/new_text/g' "$file"
    done
    EDITED!!!: Important change made. Otherwise it could just empty all the affected files. Now it should be safe.

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    20
    Thanks for tip, I was googling in the wrong keywords.
    Now I found this:
    find . -name '*.txt' |xargs perl -pi -e 's/find/replace/g'
    Or this
    perl -pi -e 's/find/replace/g' *.txt


    Thanks any way

Posting Permissions

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