Awk substitute command issue [closed]
I am trying to open a log file and manipulate lines if required. For example
2010-01-31 00:05:59,400 -0500 | [VHX4077ff8Ze1sTnE-op51V] | [TB-bce11b:-16a2-5ed9f542] | [6C7CA345F63F835CB353FF15BD6C5E052EXX8E7A | 1000107@Superfly | 31933782 | 172.9.8.3 | DEVICE_ID_CREATED]
I need to edit column 5 and remove everything before the Superfly. Essentially remove whatever number is there and the '@' symbol. This file will have entries where column 5 does not have the number@ entry and that line will not need to be edited. And the number could be any number of digits before the @. I have tried to use awk's substitute command but I cannot get it to work.
My script:
awk -F "|" {' sub(".*@","",$5) print $5 '} test.log
awk: cmd. line:3: print $5
awk: cmd. line:3: ^ syntax error
awk -F "|" {' sub(".*@","",$5); print $5 '} test.log
Missing semicolon after the first statement.
are you editing the whole file and replacing every line with the value of column 5? if not,
awk -F"|" '$5~/@/{ sub(".*@","",$5) }{print}' OFS="|" file
精彩评论