0
I'm trying to write a short shell script to loop through a list (given by a certain command I run) line by line and push values to CSV file
a list for example:
aaa bbb ccc ddd eee fff
jjj kkk lll mmm nnn ooo
uuu vvv www xxx yyy zzz
Need to loop through this and for each line take 1st,4rd and 6th fields into variables so I can do some manipulation on them.
#!/bin/sh
#
CSVfile="/tmp/`hostname`.csv"
filter=$( command )
touch $CSVfile
#
for i in $filter
do
first=$( printf "$i" | awk {'print$1'})
fourth=$( printf "$i" | awk {'print$4'})
sixth=$( printf "$i" | awk {'print$6'})
cmd=$( cat /home/app/$first/$fourth/out | grep value | awk -F: {'print$2'})
echo `date +%d%m%Y,%H%M%S`,"$sixth","$cmd" >> $CSVfile
done
the problem here is the for loop goes field by field and not line by line. need each line goes into $i so I can parse it with "awk"
Thanks