I have a large number of CSV files in a specific directory. All have at least 41 columns with matching headers, but can be as wide as 200 columns. I need to grab just the first 40 columns and append them to create a single CSV with headers. I am relatively new and was trying to follow this example How do I keep the first 200 lines of all the csv files in a directory using bash? in combination with that one Merging contents of multiple .csv files into single .csv file. I am trying to limit it to a one-liner is possible and am thinking I need a combination of "cut" and "cat" commands. I unsuccessfully tried to run something like this:
$ for file in *.csv do cut -d ',' -f1-40 "$file" > "$file"; done
then
cat *csv > combined.csv
without any luck.
Any advice is greatly appreciated. Thank you.