Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK questions

Status
Not open for further replies.

hlyeoh

MIS
May 31, 2004
22
MY
This is my test usage of awk and I face the error of "illegal statement". I don't really where goes wrong?
can anyone help? Thanks.

#! /bin/sh

temp="temp"

cat test.dat |awk \
'BEGIN {FS="|"}
{
if [$14 != ""]; then
team_name=$14
else
team_name=$31
fi


print tmp"|"$2"|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$9"|"$10"|"$11"|"$12"|"$13"|"$team_name"|"$15"|"$16"|"$17"|"$18"|"$19"|"$20"|"$21"|"$22"|"$23"|"$24"|"$25"|"$26"|"$27
}
' tmp=$temp > test_out.dat


 
Hi

That is a mess of [tt]sh[/tt] and [tt]awk[/tt] syntax. You can not combine them. Rewrite that [tt]if[/tt] with [tt]awk[/tt] syntax :
Code:
if ($14!="") {
  team_name=$14
} else {
  team_name=$31
}

Feherke.
 
Another way:
team_name = ($14=="" ? $31 : $14)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks all :) It works!!
However,there is some error in your statement,PHV.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top