I am writing a script to setup a csv file with data parsed from another .txt file. I have a few particular columns, and how this program flows, I am using these columns to grab data from the .txt. I am just unsure on how to proceed, since I want the next column to be tied to the current iteration of things Im looking at.
The general code I have is like this:
COLUMNS=(1 2 3)
for column in "${COLUMNS[@]}"; do
echo "${COLUMNS[@]}" > someCSVFile.csv
parsedText = $(sed -n '/'$column-'/,/^${/^$/d; p}' someTextFile.txt)
for line in "${parsedText[@]}"; do
echo "${line}" >> someCSVFile.csv
done
done
When I parse the code, The text returns in a format like:
a
b
c
Which ideally, I should pass to the CSV in the second for loop which should be like:
1,2,3
a,a,a
b,b,b
c,c,c
But instead, the output will be:
1
a
b
c
2
a
b
c
3
a
b
c
Is there a way, based on iteration of the loop, that I can move to the next column of the csv?
Parker Clark is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.