开发者

Awk substitute command issue [closed]

开发者 https://www.devze.com 2022-12-19 11:56 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow si开发者_高级运维tuation that is not g
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow si开发者_高级运维tuation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号