2

I have hundreds of files of the form ~/foo.x.y. The files are

~/foo.0001.0010
~/foo.0011.0020
~/foo.0021.0030
...
~/foo.4371.4378

I want to combine all of these files into a big file ~/results/output.txt where the order is preserved. I'm fairly certain that

$ cat ~/foo* > ~/results/output.txt

accomplishes this but I'm not sure if this command will respect the ordering of my foo files. Does this command work? If not, how can I accomplish my task?

  • The examples you have given will be matched in order by foo.*, you should try to add as many examples as possible to have a greater matching surface, and better precision. – heemayl Oct 9 '16 at 15:08
3

cat will follow the order of the arguments, if you expand ~/foo* (in some shells double tab, or echo ~/foo*) you will see the order.

The order of the * wildcard is alphabetic.

SO globbing question: https://superuser.com/questions/192280/does-bashs-match-files-in-alphanumeric-order

1

From man bash:

After word splitting, unless the -f option has been set, bash scans
each word for the characters *, ?, and [.  If one of these characters
appears, then the word is regarded as a pattern, and replaced with an
*alphabetically* sorted list of filenames matching the pattern

Note alphabetically. In your case it will be:

$ cat foo.0001.0010 foo.0011.0020 foo.0021.0030

You can expand * with C-x * after typing * and before pressing Enter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.