Shell script - search and replace text in multiple files using a list of strings

前端 未结 4 1783
没有蜡笔的小新
没有蜡笔的小新 2021-01-02 11:47

I have a file \"changesDictionary.txt\" containing (a variable number of) pairs of key-value strings.

e.g.

\"textToSearchFor\" = \"theReplacementText\"

4条回答
  •  孤城傲影
    2021-01-02 12:07

    Use this tool, which is written in Perl - with quite a lot of bells and whistles - oldie, but goodie:

    http://unixgods.org/~tilo/replace_string/

    Features:

    • do multiple search-replace or query-search-replace operations
    • search-replace expressions can be given on the command line or read from a file
    • processes multiple input files
    • recursively descend into directory and do multiple search/replace operations on all files
    • user defined perl expressions are applied to each line of each input file
    • optionally run in paragraph mode (for multi-line search/replace)
    • interactive mode
    • batch mode
    • optionally backup files and backup numbering
    • preserve modes/owner when run as root
    • ignore symbolic links, empty files, write protected files, sockets, named pipes, and directory names
    • optionally replace lines only matching / not matching a given regular expression

    This script has been used quite extensively over the years with large data sets.

提交回复
热议问题