In bash
, how would you cat
all files in a directory that contains a certain string in its filename. 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.
Just:
cat *test*.csv
cat *result*.csv
For all files with test
(or in case of the second one result
) in their name.
The shell itself can easily find all files matching a simple wildcard.
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. Most shells will obey your locale, so the definition of "alphabetical order" may depend on current locale settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With