简体   繁体   English

bash cat包含文件名中某个字符串的所有文件

[英]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.

相关问题 如果同名的a.json文件包含某个字符串,则用bash重命名a.tsv文件 - Renaming a .tsv file with bash if a .json file with the same name contains a certain string Bash:复制根/当前文件夹中具有相同扩展名的所有文件,但文件名包含特定字符串的文件除外 - Bash: Copy all files with same extension in root/current folder, except those whose filename contains certain string 循环播放bash中目录中具有特定名称的所有文件 - Loop for all files with certain name in directory in bash Bash-用单个文件递归地替换特定类型的所有文件,并保留原始文件名 - Bash - replace all files, of a certain type, recursively, with a single file, retaining the original file name bash:如何显示包含特定文件的第一个目录的名称 - bash: how to display the name of the first directory that contains a certain file 猫| 在bash中按名称排序csv文件 - cat | sort csv file by name in bash 通过bash将文件夹中的某些文件转换为另一个文件 - Cat certain files of a folder into another files through bash Mac OSX Unix Bash脚本将文件夹中的所有文件捕获到一个文本文件中,最好使用文件顶部的标签 - Mac OSX Unix Bash Script to cat all files in a folder to one text file, preferrably with a label at the top of the file 将文件的 Cat 内容转换为 .txt 文件,在 bash 中具有通用模式名称 - Cat content of files to .txt files with common pattern name in bash 显示所有具有特定扩展名的文件的文件名 - Display file name of all files with certain extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM