Bash script
What is wrong with this?
for i in `seq 1 4`;do /home/andrewc/Downloads/test/ cat $i.csv >> bigfile.csv done When I run it I just get ">" on the next line I am trying to merge 4 files into 1 Thank you |
Hi,
You might try doing it this way: /home/andrewc/Downloads/test/ cat file1.csv file2.csv file3.csv file4.csv > mergedfilename.csv Good Luck |
Quote:
Quote:
|
Quote:
|
Based on the example, there is a space between the last forward slash and the cat command. ie after ../Downloads/test/
Quote:
Anyway it should be Quote:
Quote:
Have you considered that if you run it again, the result will have 8 files? So it should be Quote:
|
Ok , thanks for the info , out of all the ones given
for i in `seq 1 4`; do `cd /home/andrewc/Downloads/test` `cat $i.csv >> bigfile.csv`; done seems to be the best one , and the one that actually works so I need to change to the directory even if I am in it? |
No need to change dir if you're in it already.
Do fold your code over several lines for readability and use indentation Code:
#!/bin/bash In general when using vars in the middle of a string, use ${var} notation to ensure the parser does not get confused eg Code:
cat ${i}.csv >> bigfile.csv |
You also do not require the backticks around every command. These (or the $() construct) are only required where you wish to return information to something else, so in your first
portion you wish to return the result from seq to for, but none of the other commands are returning to anything else. |
All times are GMT -5. The time now is 02:03 PM. |