Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello. I am trying to concatenate multiple csv files using
cat, and it works. It's just that in every file besides the
first one, the first line gets deleted.This is what I'm using.
cat /combine/*.csv > /combined.csv
Does anyone know if there is a way for cat to keep all the
files intact? Thanks!

I'm not understanding why you are having this problem. It's a simple enough use of cat:
cat /combine/*.csv > /combined.csv
One thing I'd like to warn you about is the above command will not work unless you have root privileges. You are attempting to create combined.csv file in the root directory:
/combined.csv
I don't think this is a good idea even if you have the file creation rights.

Thank you for your response. I took out the path to the
actual directory and the resulting file path, so I'm not actually
creating a file on root.I think I found out why... I am not getting a end of line after
each file, squeezing the last and first entry between each file.
Is there a way for cat to insert a "end of line" character after
each file? Again, Thanks for your help!

You're welcome. How silly of me! I've seen this issue before.
One fix is to add a newline to the end of the offending file. Do something like this:
echo "" >> myfile.csv
I don't think there's anything that cat alone can do, but this script lists out each file individually, appends the file to the combined.csv file, and appends a newline to the combined.csv file:
#!/bin/kshls -1 *.csv|while read file
do
echo "$file" >> combined.csv
echo "" >> combined.csv
done

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |