I am trying to collect text files from multiple subdirectories and concatenate them into a single file per subdirectory. There may be a much better way of doing this but my question is, how does one call multiple cat commands from a bash script? Here is an example:
#!/bin/bash cat "./directory_1/"*.txt > "directory_1.txt" cat "./directory_2/"*.txt > "directory_2.txt"
If I keep all the commands on the same line, seperated by semicolons, it works. For example:
#!/bin/bash cat "./directory_1/"*.txt > "directory_1.txt";cat "./directory_2/"*.txt > "directory_2.txt"
But if I need to call say 20 directories, the script becomes very hard to read.
I expected the first example to run each cat command, however, the following error was thrown:
line 2: $'\r': command not found : No such file or directorydirectory2.txt
It looks like I have a problem with the newline character. I am trying to run this command on the Ubuntu shell for Windows 10.