0

I have some files in a directory A. From another directory B, I want to concatenate them in one single file. I use the command line cat like cat path_A/* > my_file_output

I have an error that say No such file or directory

cat /data/chei2402/ibra/test_infernal/nbF-050_nbSeqs-[20-40]/Train/* > nbF50_train.fasta
cat: '/data/chei2402/ibra/test_infernal/nbF-050_nbSeqs-[20-40]/Train/*': No such file or directory

When I enter the directory A. and execute either

cat * > my_file_output` 

or

cat * > path_B/my_file_output

it works fine.

But I want

cat path_A/* > my_file_output

Thank you for your help.

7
  • 2
    Are there literal []s in the directory names? If so, the shell is expanding it as an expansion.
    – jsbillings
    Commented Mar 15, 2021 at 15:56
  • @jsbillings , yes, one folder in the path is nbF-050_nbSeqs-[20-40] that contains indeed the [] in it. Beside renaming the folder name, how can I solve this issue, because i have lot off folder like this nbF-var_i_nbSeqs-[min-max] where var_i, min and max are integers. Thanks.
    – ibra
    Commented Mar 15, 2021 at 16:02
  • You can also do something like find /data/chei2402/ibra/test_infernal/ -type f -exec cat {} >> ~/results.txt \; if you know they are all text files you need.
    – cutrightjm
    Commented Mar 15, 2021 at 16:15
  • @cutrightjm , thank you for your suggestion. In my case, I can't use find, because there are a lot of folders (as I explain in my previous comment) that contain similar files.
    – ibra
    Commented Mar 15, 2021 at 17:12
  • That doesn't make sense, since you are just wildcard catting anyways. Just run find on the folder you are wanting to concatenate everything in. If you don't want to go deeper, set maxdepth.
    – cutrightjm
    Commented Mar 15, 2021 at 18:58

1 Answer 1

4

You must either escape your [ and ] to \[ and \] or put the path in quotes to prevent these globs to expand, make sure to keep the * out of the quotes:

cat '/data/chei2402/ibra/test_infernal/nbF-050_nbSeqs-[20-40]/Train/'* > nbF50_train.fasta
1
  • Thank you very much. In fact I have tried putting the whole path in quotes, but it didn't work, because of *. So your sentence "make sure to keep the * out of the quotes" is very very important for me.
    – ibra
    Commented Mar 15, 2021 at 17:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .