How to read a single column CSV file in bash? -
i relatively new bash/programming in general.
i have single column csv looks this:
domain1.com domain2.com domain3.com domain4.com
i want run through each entry , it. here code:
foo(){ i=0 while read -a line; echo ${line[i]} ((i++)) done < myfile.csv }
and nothing happens. have figured out if change file i'm pointing @ to:
done< <(grep '' myfile.csv)
it work, spit out last line of csv, this:
domain4.com
again, beginner , teaching myself stuff, explanations want give answers appreciated!
edit appears new problem removing ^m character csv file. once figure out how this, mark answer here works me.
looks have 2 issues:
- your lines ending
\r
- there no new line or
\r
@ end of last line
to fix issue use script:
echo >> file.csv while read -r line; echo "$line"; done < <(tr '\r' '\n' < file.csv)
Comments
Post a Comment