awk -F'|' '{ print $5 }' in perl

Hi guys
i need you help its urgent..
im trying to translate this file processing command in Perl.
awk -F'|' '{ print $5 }'

any ideas :wink:
Regards

hello,

try,split() in perl and then grab $arr[5].

perl -wln -e 'my @arr=split("|",$_);print $arr[5];' file1 file2 ...

Regards,
Gaurav.

Thanks man
it not working...
here is a smaple of my log :

2010-07-12  00:33:52|Raid-bridge|5492645293293831725|HTTP|Get|File allowed|x.x.x.x|

if i run :

awk -F'|' '{ print $5 }' log  
the results is :Get

however if i run :

perl -wln -e 'my @arr=split("|",$_);print $arr[5];'

results: 0
Thanks
regards
Raid

That's because Perl, contrary to awk, starts indexing its fields at 0. This should work:

perl -ple '@a = split /\|/; $_ = $a[4];' log

Works great
Thanks guys
:slight_smile:

i have an exam for linux and i just cannot understand when i should use print $5 or $6.

i need to find the month and the date so somebody use print $5 somebody print 6 and i am confused.

thanks..

perl -F'\|' -lape '$_=$F[4]'

---------- Post updated at 06:44 PM ---------- Previous update was at 06:42 PM ----------

Nevermind, I just noticed that the problem was addressed about 3 weeks ago.