pasaico
December 30, 2013, 9:29am
1
i have an email list in file.txt with comma separated
line1 - FIELD1,pippo@gmail.com,darth@gmail.com
line2 - FIELD2,pippo@gmail.com,darth@gmail.com,sampei@gmail.com
output=(awk -F ',' -v var="$awkvar" '$1==var {print $2,$3,$4}' spreadsheet.txt)
but awk delete some letters at the beginning of the output
echo "$output"
ippo@gmail.com darth@gmail.com
pippo@gmail.com darth@gmail.com sampei@gmail.com
but if i remove $4
ouput=(awk -F ',' -v var="$awkvar" '$1==var {print $2,$3}' spreadsheet.txt)
echo "$output"
it is correct display for line1 but not for line2:
pippo@gmail.com darth@gmail.com
pippo@gmail.com darth@gmail.com
What am I doing wrong?
ctsgnb
December 30, 2013, 9:32am
2
Where did you close the single quote that you opened at :
'$1==var
?
What is the content of your $awkvar
variable ?
pasaico
December 30, 2013, 9:39am
3
i have modified
my copying error
ctsgnb
December 30, 2013, 9:53am
4
What is the content of your $awkvar
variable ? (wouldn't you use ~
rather than ==
? ... of course depending on what you have and what you need).
Did you export it ?
Did you make sure your input file does not contain some invisible character ?
(editing it in vi
for example and using :set list
, or using -v
option of cat
)
pasaico
December 30, 2013, 10:00am
5
$awkvar is match with FIELD1, FIELD2, FIELD3
awk print line that is equal to $awkvar
input file is correct, i have check it with cat -v
ctsgnb
December 30, 2013, 10:04am
6
How big is your input file ? ... a variable has a limited length
by the way did you try
output=$( ... )
instead of
output=( ... )
?
Please provide a full example of input and code you use
pasaico
December 30, 2013, 10:29am
7
for fullname in *.zip; do
filename="${fullname##*/}"
awkvar=$(echo $filename | cut -d_ -f2-2)
output=$(awk -F ',' -v var="$awkvar" '$1==var {print $2,$3}' spreadsheet.txt)
echo $output
$awkvar is FIELD1,FIELD2,FIELD3 ecc. ecc.
ctsgnb
December 30, 2013, 10:38am
8
If it is your "full" code ... the done
is obviously missing.
did you try replacing
output=$(awk -F ',' -v var="$awkvar" '$1==var {print $2,$3}' spreadsheet.txt)
echo $output
with something like
awk -F ',' -v var="$awkvar" '$1==var {print $2,$3}' spreadsheet.txt >>output
done
cat output
(What is in blue may not be necessary, it depends on what you expect and what you get)
Please provide what you get when entering the following commands :
ls -1 | grep .zip$
cat spreadsheet.txt
RudiC
December 30, 2013, 11:48am
9
Sounds like a non-*nix input file. Please post spreadsheet.txt and/or a hexdump of it.