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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk -F'|' '{ print $5 }' in perl
# 1  
Old 07-12-2010
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 Smilie
Regards
# 2  
Old 07-12-2010
hello,

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

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

Regards,
Gaurav.
# 3  
Old 07-12-2010
Thanks man
it not working...
here is a smaple of my log :
Code:
2010-07-12  00:33:52|Raid-bridge|5492645293293831725|HTTP|Get|File allowed|x.x.x.x|

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

however if i run :
Code:
perl -wln -e 'my @arr=split("|",$_);print $arr[5];'

results: 0
Thanks
regards
Raid

Last edited by pludi; 07-12-2010 at 05:56 AM.. Reason: CODE TAGS, PLEASE....
# 4  
Old 07-12-2010
That's because Perl, contrary to awk, starts indexing its fields at 0. This should work:
Code:
perl -ple '@a = split /\|/; $_ = $a[4];' log

# 5  
Old 07-12-2010
Works great
Thanks guys
Smilie
# 6  
Old 08-06-2010
hi i need help please

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..
# 7  
Old 08-06-2010
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in solving to obtain desired print output using awk or perl or any commands, Please help!!

I have an file which have data in lines as follows ad, findline=24,an=54,ab=34,av=64,ab=7989,ab65=34,aj=323,ay=34,au=545,ad=5545 ab,abc,an10=23,an2=24,an31=32,findline=00,an33=23,an32=26,an40=45,ac23=5,ac=87,al=76,ad=26... (3 Replies)
Discussion started by: deepKrish
3 Replies

2. Shell Programming and Scripting

Awk: Print count for column in a file using awk

Hi, I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1). Input: 919143110065 919143110065 919143110052 918648846132 919143110012 918648873782 919143110152 919143110152 919143110152... (2 Replies)
Discussion started by: siramitsharma
2 Replies

3. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

Hello all According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values example, running this script/command like ./script.sh xxapp I would expect as output: 102 116 112 ./script.sh xxapp2... (2 Replies)
Discussion started by: cabrao
2 Replies

4. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

5. Shell Programming and Scripting

perl or awk print strings between words

hi everyone, 1.txt 981 I field1 > field2.a: aa, ..si01To:<f:a@a.com>From: <f:a@a.com>;tag=DVNgfRZBZRMi96 <f:a@1:333>;ZZZZZ: 12345 the output field1 field2 <f:a@a.com> the output is cut the string 3rd and 5th field, and get the value betwee "To:" and "From:", please advice. ... (1 Reply)
Discussion started by: jimmy_y
1 Replies

6. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

7. Shell Programming and Scripting

using perl to print 1 or 0

Suppose u have a file FILE A ABCA10 DIFF VALUES P203S POLY ABCA1 DIFF VALUES A1046D ABCA4 DIFF VALUES D846H POLY ABCA4 DIFF VALUES I1846T POLY ABCA4 DIFF VALUES Wa ABCA4 DIFF VALUES WA ABCA4 DIFF VALUES Wb and u want to print that if FILE A have POLY so print 0 otherwise 1 means... (1 Reply)
Discussion started by: cdfd123
1 Replies

8. Shell Programming and Scripting

using perl or awk to print output

suppose u have file File A A -> G C->D A -> R P->A File B A=1 C=2 D=3 E=4 F=5 G=6 H=7 I=8 K=9 L=10 M=11 (5 Replies)
Discussion started by: cdfd123
5 Replies

9. Shell Programming and Scripting

How do I get awk to print a " in it's print part?

The line is simple, use " '{ print $1"]"$2"\"$3THE " NEEDS TO GO HERE$4 }' I've tried \", "\, ^" and '"" but none of it works. What am I missing? Putting in the [ between $1 and $2 works fine, I just need to do the same with a ". Thanks. (2 Replies)
Discussion started by: LordJezo
2 Replies

10. UNIX for Dummies Questions & Answers

perl print command

Hi, I am running this command in perl print "this is a test message @1.00 pm\n" but the output i am getting as this is a test message .00 pm pls help, how to get the proper output (2 Replies)
Discussion started by: vasikaran
2 Replies
Login or Register to Ask a Question