Hi,
I need some ideas and help for creating a unix script. I have the following input file. I need the output like this:
if the first column is 'R', print 'R';
if the first column is 'A', then check the 2nd column
if 2nd col contains 'FA0', print
'R' 'FA01FBxx'
else, print
'A'
I was trying to use awk, like
cat input_file | awk ' $2 ~ /FA0/ {print "R" } '
or
cat input_file | awk '/FA0/{print "R" }'
Both of the scripts give me six 'R's.
How can I put the logic if Col 2 ($2) doesn't contains 'FA0'? Can I do something like this:
cat input_file | awk ' if($2 ~ /FA0/) {print "R" } \
else {print "A" }'
?
Then how I can get FA01FBxx from $2?
Thank you.
David
1. Input file
R 20051230^]^^^\AM21^\ANR^\F318421^\FA01^\FB52^\FQREFERENCE
R 20051230^]^^^\AM21^\ANR^\F318451^\FA01^\FB52^\FQREFERENCE
A 20060105^^^\AM21^\ANR^\F392821^\FA01^\FB70^^^\AM22^\EM1^\D20001111^M^M
A 20060105^^^\AM21^\ANR^\F392941^\FA01^\FB70^^^\AM22^\EM1^\D20001111^M^M
A 20060105^^^\AM25^\C1470^^^\AM23^\F50000010{^\F610{^\AV2^\F90000000{^\FM4^M^M
A 20060105^^^\AM25^\C14702MUITCTC65...FA01^\FB70^^^\AM22^\EM1^\D20001111^M^M
A 20060105^^^\AM21^\ANR^\F393271^\FA01^\FB70^^^\AM22^\EM1^\D20001111^M^M
2. Output:
R FA01FB52
R FA01FB52
R FA01FB70
R FA01FB70
A
R FA01FB70
R FA01FB70
I need some ideas and help for creating a unix script. I have the following input file. I need the output like this:
if the first column is 'R', print 'R';
if the first column is 'A', then check the 2nd column
if 2nd col contains 'FA0', print
'R' 'FA01FBxx'
else, print
'A'
I was trying to use awk, like
cat input_file | awk ' $2 ~ /FA0/ {print "R" } '
or
cat input_file | awk '/FA0/{print "R" }'
Both of the scripts give me six 'R's.
How can I put the logic if Col 2 ($2) doesn't contains 'FA0'? Can I do something like this:
cat input_file | awk ' if($2 ~ /FA0/) {print "R" } \
else {print "A" }'
?
Then how I can get FA01FBxx from $2?
Thank you.
David
1. Input file
R 20051230^]^^^\AM21^\ANR^\F318421^\FA01^\FB52^\FQREFERENCE
R 20051230^]^^^\AM21^\ANR^\F318451^\FA01^\FB52^\FQREFERENCE
A 20060105^^^\AM21^\ANR^\F392821^\FA01^\FB70^^^\AM22^\EM1^\D20001111^M^M
A 20060105^^^\AM21^\ANR^\F392941^\FA01^\FB70^^^\AM22^\EM1^\D20001111^M^M
A 20060105^^^\AM25^\C1470^^^\AM23^\F50000010{^\F610{^\AV2^\F90000000{^\FM4^M^M
A 20060105^^^\AM25^\C14702MUITCTC65...FA01^\FB70^^^\AM22^\EM1^\D20001111^M^M
A 20060105^^^\AM21^\ANR^\F393271^\FA01^\FB70^^^\AM22^\EM1^\D20001111^M^M
2. Output:
R FA01FB52
R FA01FB52
R FA01FB70
R FA01FB70
A
R FA01FB70
R FA01FB70