Help with Awk finding and replacing a field based on a condition

Hi everybody,

I'm trying to replace the $98 field with "T" if the last field (108th) is T

I've tried

 awk 'BEGIN{OFS=FS="|"} {if ($108=="T")sub($98,"T"); print}' test.txt

but that doesn't do anything

also tried

  awk 'BEGIN{OFS=FS="|"}{ /*T.$/ sub($98,"T")} { print}'  test.txt

but that doesn't seem to do anything either

---------- Post updated at 02:01 PM ---------- Previous update was at 01:52 PM ----------

I've also tried the below and that doesn't work either

awk -F"|" '/T.$/ sub( $98,"T")' test.txt

Your first command seems to have correct syntax.

$ cat sample5.txt
A|T|X|G
G|X|T|A
G|T|A|X

$ awk 'BEGIN {OFS=FS="|"} {if ($2=="T")sub($1,"T"); print }' sample5.txt
T|T|X|G
G|X|T|A
T|T|A|X
1 Like

thanks =)

data integrity issue

column $108 acutally had a space after the T

---------- Post updated at 02:22 PM ---------- Previous update was at 02:21 PM ----------

 awk 'BEGIN{OFS=FS="|"} /\|T.$/{$98="T"}1'

works