I'm looking for some help with my script. I'm trying to loop over a bunch of CSV files, cut out the 3rd column, and append that to an output file as a new column. Here's what I have so far:
#!/bin/bash
for n in ~/sampledir/*
do
awk -F "," '{print $3","}' $n >> output.csv
done
The output looks like this:
Column3,
3,
33,
333,
3333,
33333,
Column3,
3,
33,
333,
3333,
33333,
Column3,
3,
33,
333,
3333,
33333,
Column3,
3,
33,
333,
3333,
33333,
Column3,
3,
33,
333,
3333,
33333,
What I want is for the new information to be appended to the CSV in columns, so rather than the output above, I want this:
Column3,Column3,Column3,Column3,Column3,Column3,
3,3,3,3,3,3,
33,33,33,33,33,33,
333,333,333,333,333,333,
3333,3333,3333,3333,3333,3333,
33333,33333,33333,33333,33333,33333,
Any guidance would be helpful. Thanks y'all.