i need read each lines of csv file , save values variables.
exemple of csv file multiple lines :
value1;value2;value3 value4;value5;value6 i have :
enreg in `cat ../files/inputs/file.csv` info1= `echo $enreg | awk -f ';' '{ print $1}'` info2= `echo $enreg | awk -f ';' '{ print $2}'` info3= `echo $enreg | awk -f ';' '{ print $2}'` echo "info1= $info1" echo "info2= $info2" echo "info3= $info3" echo "$info3;$info2;$info1" >> ../files/output/files.csv done i have following result in console:
info1= value1 value4 info2= value2 value5 info3= value3 value6 but need write in second csv file:
info1= value1 info2= value2 info3= value3 info1= value4 info2= value5 info3= value6 thanks , have nice day.
_______________________________________________________________________________
update
my csvmatricule.csv :
value1;value2;value3 value4;value5;value6 my csvmatricule.ks :
while ifs=";" read -r f1 f2 f3 echo "info1=$f1" echo "info2=$f2" echo "info3=$f3" done < ../files/inputs/csvmatricule.csv my console result :
info1=value1 info2=value2 info3=value3 the result of cat -vet ../files/inputs/csvmatricule.csv :
value1;value2;value3$ value4;value5;value6 why second line of csv isn't take in count ??
what using awk command this?
$ awk -f";" '{for (i=1;i<=nf;i++) printf "info%d=%s\n", i, $i}' file info1=value1 info2=value2 info3=value3 info1=value4 info2=value5 info3=value6 this loops through ;-separated fields , prints them info + number.
if number of fields fixed, can use while loop:
while ifs=";" read -r f1 f2 f3 echo "info1=$f1" echo "info2=$f2" echo "info3=$f3" done < file this way loop through file sequentially, instead of for ... in cat .... way, every loop in while reads line. also, giving more 1 argument read, each ;-separated field assigned corresponding variable. 1st $f1, 2nd $f2 , rest $f3.
if need store these values variables, say: source <( command ).
Comments
Post a Comment