awk - to -- PERL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - to -- PERL
# 1  
Old 06-14-2010
awk - to -- PERL

DEAR ALL,

i am using following command to fetch some records from more then 50000 files... command is taking more time ....

can i have perl command for the same...( i am New to perl )

Code:
awk -F "|" '{ if($4==3244898 && $5==5000185) print $66}' *.DATA

# 2  
Old 06-14-2010
Quote:
Originally Posted by arvindng
...
can i have perl command for the same...( i am New to perl )

Code:
awk -F "|" '{ if($4==3244898 && $5==5000185) print $66}' *.DATA

Code:
perl -F[\|] -lane 'print $F[65] if ($F[3]==3244898 and $F[4]==5000185)' *.DATA

tyler_durden
# 3  
Old 06-14-2010
With 50,000 files and a minimum of 66 fields, you might want to think about optimization. Perl running the same algorithm as awk will not be faster, and may be slower. However, with Perl, you would be able to change how the files are processed and may be able to speed it up.

How big are the files? How many fields? How often is the print statement triggered?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Converting awk to perl

Hello. I'm trying to convert an awk script I wrote to perl (which I just started self-teaching). I tried the a2p command but I couldn't make sense of most of it. Here was the awk code: BEGIN{ FS = "," print "NAME\tLOW\tHIGH\tAVERAGE" a=0 } { if(a==0){ a+=1 (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. Shell Programming and Scripting

What is the equivalent of NR (awk) in perl?

Hello, I searched online; it seems that perl use $NR as NR in awk; however it does not work for me. For example, how to re-write the following awk using perl: awk '{ print NR}' inputfile---------- Post updated at 01:55 PM ---------- Previous update was at 12:49 PM ---------- I found... (2 Replies)
Discussion started by: littlewenwen
2 Replies

3. Shell Programming and Scripting

awk and perl grouping.

Hello folks. After awk, i have decided to start to learn perl, and i need some help. I have following output : 1 a 1 b 2 k 2 f 3 s 3 p Now with awk i get desired output by issuing : awk ' { a = a FS $2 } END { for ( i in a) print i,a }' input 1 a b 2 k f 3 s p Can... (1 Reply)
Discussion started by: Peasant
1 Replies

4. Shell Programming and Scripting

get value between <abc and > by perl, awk

Hi Everyone, cat 1.txt a <abc b vfff c 000> d 4444 the output is: <abcvfff000> by using perl or awk, can get the value betwee "<abc" and ">", assume 1.txt has lots of those tags, so the output can filter out all those values. Please advice. Thanks (4 Replies)
Discussion started by: jimmy_y
4 Replies

5. Shell Programming and Scripting

awk vs perl

awk -F "|" '{print $2$3$4 upto $30}' file1 > file2 Same logic, i want to write it in perl I tried #!/bin/usr/perl my $line; open FH, "<file1" or die " Can't open file $!"; open FH1, ">file2" or die "Can't open file "; while (<FH1>){ $line = (split /\|/,$_); print FH2 $line;... (3 Replies)
Discussion started by: pritish.sas
3 Replies

6. Shell Programming and Scripting

Using perl grep and awk

I have a script to get server information i wrote in perl because i would like to learn it (and I use it for work). It works great, however i would like to know if there is a good way to reduce the following line. Sean (6 Replies)
Discussion started by: insania
6 Replies

7. Shell Programming and Scripting

awk or perl

hi all I am new to awk/perl I would appreciate it if you could help! how do I read a sub folder and their files. e.g. simulation/10ms/router1.dat, router2.dat,..., router16.dat simulation/100ms/router1.dat, router2.dat,..., router16.dat simulation/300ms/router1.dat,... (14 Replies)
Discussion started by: mmoses
14 Replies

8. Shell Programming and Scripting

awk command with PERL

Hi All, My Input file looks like below: Input: 100,200,300 $fw=`head -1 test.csv | awk -F, '{print \$1}'`; $fw="'$fw" $fw="$fw'" print $fw Output:'100' I want the first field to be printed in single quotes ('') like above. I could get the ouptput but the problem is single... (6 Replies)
Discussion started by: kmkbuddy_1983
6 Replies

9. Shell Programming and Scripting

awk to perl convert

Dear Collegue Do anybody help me to convert this AWK script to Perl script { for (i = 2; i <= length ($0); i++) { x = substr($0, i , 1) if (c > 0) { b = b x if (x == "(") c++ ... (2 Replies)
Discussion started by: jaganadh
2 Replies

10. Shell Programming and Scripting

AWK embeded PERL

Hello Guys, I am refering to this great forum once again for help. After various attempts at this, I am still failing to obtain the desire effect. I have to write a perl script which: 1- reads two values from the user (e.g name & passwd) 2- check each value against a file containing the... (7 Replies)
Discussion started by: bionicfysh
7 Replies
Login or Register to Ask a Question