I am trying to print the columns in a CSV file. The CSV file is as below:
Account,Data,Address,Name
A1101,100,"303,SCA,JDM",Ram
A1102,100,"303,SCA,JDM",Ram
And I have used the below Bash code to print the pattern.
patterns="$(cat csv_file3.csv |
tail -n +2 |
sort -k 2 |
cut -d , -f 1,3,4 |
uniq |
tr -d ' ')"
echo "$patterns"
While I was executing in Git-Bash, the pattern is being printed as below:
As you can see, only a part of the 3rd column is being printed. Is it possible to print the format correctly? Below is the expected output.
Account,Address,Name
A1101,"303,SCA,JDM",Ram
A1102,"303,SCA,JDM",Ram
2
try to solve it by gawk :
$ gawk -k 'NR>=2{printf ("%s,"%s",%sn", $1,$3,$4);}' csv_file3.csv
A1101,"303,SCA,JDM",Ram
A1102,"303,SCA,JDM",Ram
cut -d,
will consider the "303
and JDM"
is a single one field.