[英]bash cat all files that contains a certain string in file name
In bash
, how would you cat
all files in a directory that contains a certain string in its filename. 在
bash
,你会如何cat
在包含在它的文件名一定字符串的目录中的所有文件。 For example I have files named: 例如,我有名为的文件:
test001.csv
test002.csv
test003.csv
result001.csv
result002.csv
I want to cat
all .csv
that contains the string test
in the file name together, and all .csv
that contains the string result
in the file name together. 我想
cat
所有.csv
包含字符串test
在文件名一起,和所有.csv
包含字符串result
中的文件名一起。
Just: 只是:
cat *test*.csv
cat *result*.csv
For all files with test
(or in case of the second one result
) in their name. 对于名称中包含
test
(或第二个result
)的所有文件。
The shell itself can easily find all files matching a simple wildcard. shell本身可以轻松找到与简单通配符匹配的所有文件。
cat *test*.csv >testresult
You want to take care so that the output file's name does not match the wildcard. 您需要注意,以便输出文件的名称与通配符不匹配。 (It's technically harmless, but good practice.)
(这在技术上是无害的,但是很好的做法。)
The shell will expand the wildcard in alphabetical order. shell将按字母顺序展开通配符。 Most shells will obey your locale, so the definition of "alphabetical order" may depend on current locale settings.
大多数shell都会遵循您的语言环境,因此“字母顺序”的定义可能取决于当前的语言环境设置。
这是非常简单的方法
cat `find . -name "*test*.csv"`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.