views:

154

answers:

2

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

Thanks for any help!!

+1  A: 
awk -F "|" {' sub(".*@","",$5); print $5 '} test.log

Missing semicolon after the first statement.

Mech Software
Thanks MechS, I am still getting an error after trying your command:awk: sub(".*@","",$5); print $5 awk: ^ syntax error
roacha
awk -F "|" {' sub(".*@","",$5); print $5 '} test.logfrom my linux command line with your sample data yields "SuperFly"Your awk interpreter may be requiring a ; after the last statement tooawk -F "|" {' sub(".*@","",$5); print $5; '} test.logMine did not.
Mech Software
As an FYI, I generally find it easier to use the -f parameter and edit a file. It's more readable down the road and a lot of editors might have noted the bad syntax.
Mech Software
Sorry, I don't understand what is happening with my setup. I am running Suse Linux 10. Is there another way to do this via a script? I will need this to run everyday on multiple large files and change this column. Script now:awk -F "|" {' sub(".*@","",$5); print $5; '} test.logSame error:awk: sub(".*@","",$5); print $5; awk: ^ syntax error
roacha
I have also tried the same script and data on a CentOS 5 system. And I get the same error.
roacha
Working fine on my ubuntu. Try putting the code {sub(".*@","",$5); print $5;} in a file and running awk with the -f parameter to the .awk file with this code in it. The only other thing I can think of is the single quotes '. I'm not sure why you have those on the inside of the {} braces. Awk treats each set of braces as a rule against input.
Mech Software
awk -F "|" '{ sub(".*@","",$5); print $5; }' test.log worked fine on CentOS. It was your quotes throwing you off along with other syntax errors.
Mech Software
Yep, you got it Mech. I just ran it with moving the single quotes outside the {} and it worked like a charm. Thanks for all your help!
roacha
A: 

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
ghostdog74