更改多个文件 [英] Change multiple files
本文介绍了更改多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下命令正确更改了 2 个文件的内容.
The following command is correctly changing the contents of 2 files.
sed -i 's/abc/xyz/g' xaa1 xab1
但是我需要做的是动态更改几个这样的文件,我不知道文件名.我想编写一个命令,该命令将从当前目录中读取以 xa*
开头的所有文件,并且 sed
应该更改文件内容.
But what I need to do is to change several such files dynamically and I do not know the file names. I want to write a command that will read all the files from current directory starting with xa*
and sed
should change the file contents.
推荐答案
更好:
for i in xa*; do
sed -i 's/asd/dfg/g' $i
done
因为没人知道有多少文件,而且很容易打破命令行限制.
because nobody knows how many files are there, and it's easy to break command line limits.
当文件过多时会发生以下情况:
Here's what happens when there are too many files:
# grep -c aaa *
-bash: /bin/grep: Argument list too long
# for i in *; do grep -c aaa $i; done
0
... (output skipped)
#
这篇关于更改多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文