Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Linux, if I have a bunch of text files is there a simple script to merge them into one file?

Tags:

shell

For example suppose I have 1.csv, 2.csv, ... , 20.csv. Is there a simple shell script where I can merge everything into merged.csv?

like image 926
deltanovember Avatar asked Nov 19 '25 08:11

deltanovember


1 Answers

Use cat to concatenate them.

cat *.csv > merged.csv

As @sarnold points out this will concatenate them out of order. If that's important, use his for loop suggestion, or this xargs pipeline:

ls *.csv | sort -n | xargs cat > merged.csv
like image 53
John Kugelman Avatar answered Nov 21 '25 22:11

John Kugelman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!