Find and replace text in a file between range of lines using sed

前端 未结 2 449
闹比i
闹比i 2020-12-16 15:57

I have a big text file (URL.txt) and I wish to perform the following using a single sed command:

  1. Find and replace text \'google\' with \'facebook\'

相关标签:
2条回答
  • 2020-12-16 16:29

    You can use sed addresses:

    sed '19,33s/google/facebook/g' file
    

    This will run the substitution on lines between and including 19 and 33.

    The form of a sed command is as follows:

    [address[,address]]function[arguments]
    

    Where 19,33 is the addreses,
    substitute is function
    and global is the argument

    0 讨论(0)
  • 2020-12-16 16:34

    the above answer ALMOST worked for me on Mac OSX.

    sed '19,33s/google/facebook/' file

    worked perfectly without braces.

    sed '19,$s/google/facebook/' file

    works until the end of the file as well.

    0 讨论(0)
提交回复
热议问题