I'm trying to show the field next to the name that I find with awk command in spredsheet.xls
I have this situation;
**Column1** *Column2*
**PIPPO** *pippo@gmail.com darth@gmail.com*
**PLUTO** *pluto@gmail.com duck@gmail.com*
**WATER** *drink@gmail.com water@gmail.com*
how do I search for a word in column 1 and display the contents in column 2?
awk '$1 == "PIPPO"' spreadsheet.xls
this command show:
PIPPO pippo@gmail.com darth@gmail.com
Update
this is my code ---- Column1 (PIPPO, PLUTO, WATER) and awkvar is the same thing----
for fullname in /*.zip; do
filename="${fullname##*/}"
awkvar=$(echo $filename | cut -d_ -f2-2)
awk -v var="$awkvar" '{print $2,$3}' spreadsheet.xls
done
but this not work. How do I put a pattern variable in awk?
Update 2
i have update list xls with comma separated
FIELD1,pippo@gmail.com,darth@gmail.com
FIELD1,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
output=(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?
Probably you want to display only 2nd column. Use this awk:
EDIT:
If you want to display all columns after 1st columns then use:
You can use the following:
That will output:
The format is not clear to me, so depending on how it is you may need
{print $2, $3}
.As said in comments, based on your updated code you can use this to use the bash var inside
awk
: