replace contant with multiple files

递归当前文件夹,替换所有.html, .js结尾的文件中包含有/cdn内容的文本为https:cdn

sed -i ‘s//cdn/https:cdn/g’ grep "/cdn" -rl --include='*.html' --include='*.js' ./
format
sed [-e] instruction file(s)

[root@localhost teacher2]# sed --help
Usage: sed [OPTION]… {script-only-if-no-other-script} [input-file]…

-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
–follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-c, --copy
use copy instead of rename when shuffling files in -i mode
-b, --binary
does nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX (
open files in binary mode (CR+LFs are not treated specially))
-l N, --line-length=N
specify the desired line-wrap length for the `l’ command
–posix
disable all GNU extensions.
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
–help
display this help and exit
–version
output version information and exit

If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.

GNU sed home page: http://www.gnu.org/software/sed/.
General help using GNU software: http://www.gnu.org/gethelp/.
E-mail bug reports to: [email protected].
Be sure to include the word sed'' somewhere in theSubject:’’ field.
instruction
1s/to_find/replace/g

1s is start from first line, g is end with last line

file(s)
one file or multi files

test.txt:
just one file with name test.txt
*.txt:
all .txt files in current directory with depth equal one
find -name '*.txt' -type f ./:
use command to find all *.txt files in current directory

猜你喜欢

转载自blog.csdn.net/taoxb_csdn/article/details/85611692