I have the following DATA infile
Cross,Tim,43560,0000000000,0000000000
Smith,Sam,00000,4192125555,4192088888
Williams,Jill,00000,0000000000,4199139999
Wright,Mark,27645,0000000000,7042964444
Alston,Jacob,00000,2025674962,0000000000
I need the output to label the corresponding fields if they are populated. The target fields are ZIP, HOME, and WORK which are $3,$4,$5 columns respectively from the infile. If the value of any of the fields is null or 0, then the output field label corresponding will be empty. Here is how the expected output should look:
Cross,Tim,43560,ZIP,0000000000,,0000000000,
Smith,Sam,00000,,4192125555,HOME,4192088888,WORK
Williams,Jill,00000,,0000000000,,4199139999,WORK
Wright,Mark,27645,ZIP,0000000000,,7042964444,WORK
Alston,Jacob,00000,,2025674962,HOME,0000000000,
I've attempted to use AWK but can't seem to successfully do an if condition for more than 1 value against the print
code that hasn't worked
zip1=ZIP
home1=HOME
work1=WORK
awk -F , '{
if ($3 ~ "00000")
"'${zip1}'"=="";
if ($4 ~ "0000000000")
"'${home1}'"=="";
if ($5 ~ "0000000000")
"'${work1}'"=="";
print $1 "," $2 "," $3 "," "'${zip1}'" "," $4 "," "'${home1}'" "," $5 "," "'${work1}'"}' $inputfile
This code just prints the vars without considering the if statements. If I print directly under 1 if statement, it will only print against that if of course. Not sure how to have the single print recognize each if condition.