Perl script doubt?


View Poll Results: Perl
Continuous practice 1 50.00%
Go ahead 1 50.00%
Achieve 0 0%
Learn 0 0%
Voters: 2. This poll is closed

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script doubt?
# 1  
Old 10-06-2008
CPU & Memory Perl script doubt?

Dear friends,

I have two files. In first file first column ($1), i have numbers.

The second file containes, the same number in the fourth column($4).

I need a output file, matching the first file column 1 with second file column 4. The main thing is the output file lines will be sorted without changing the line.


Eg:

File1:
123
124
125

File 2:

we are at 123 from unix
we are at 124 from linux
we are at 123 at script
we are at 567 at perl
we are at 125 at awk

Desired Output:
we are at 123 from unix
we are at 123 at script
we are at 124 from linux
we are at 125 at awk
# 2  
Old 10-06-2008
If the number is always in the fourth column and all you need is to sort numerically, you don't need Perl at all.

Code:
sort -rn -k4 file2

What's with the poll?
# 3  
Old 10-06-2008
not sorting, search and to do arithmetic..

Hi thanks,

But my question is not like sorting.

I am explaining little detaily:

FIle 1:

123 678 345 hi 6798
452 789 256 bi 8746
145 689 124 ji 435
456 690 345 ki 789

File 2:
345
256
124

Expected Output:

The outfile should rearrange according to the fourth column of file1, matching with the first column of file2.

Like:

123 678 345 hi 6798
456 690 345 ki 789
452 789 256 bi 8746
145 689 124 ji 435

Then the column 5 should be added for 345 matching individuallly, 256 invidually, 124 individually.

Like:
the addition of 345 match 5th column is 6798+789 = 7587
the addition of 256 macth 5th column is 8746
the addition of 124 match 5th column is 435

Thanks in advance for your reply,
Vasanth



Quote:
Originally Posted by era
If the number is always in the fourth column and
all you need is to sort numerically, you don't need Perl at all.

Code:
sort -rn -k4 file2

What's with the poll?
# 4  
Old 10-06-2008
This question is asked a lot here, although the answer is usually in awk. Search for NR==FNR and throw in Perl to see how it's done in Perl.

https://www.unix.com/cfmgoogle.php?cx...sa=Search#1061
# 5  
Old 10-06-2008
I have closed the poll. I see no purpose it serves.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl doubt

Hi, Please help me to understand the following code: perl -lne 'print if "$_ " =~ /(5 (?:\d+ ){5})\1/' What the regular expression "?:" does? Also, whether the expression "\1" is the same as in sed (i.e) printing the elements inside pair of parentheses? (3 Replies)
Discussion started by: royalibrahim
3 Replies

2. Shell Programming and Scripting

Trivial perl doubt about FILE

Hi, In the following perl code: #!/usr/bin/perl -w if (open(FILE, "< in_file")) { while (<FILE>) { chomp($_); if ($_ =~ /patt$/) { my $f = (split(" ", $_)); print "$f\n"; } } close FILE; } Why changing the "FILE" as... (4 Replies)
Discussion started by: royalibrahim
4 Replies

3. Shell Programming and Scripting

Doubt in Perl Variable declaration

Anyone please say what is the difference between $var and ${var} in perl Sometimes $var used and sometimes ${var} used in same program. Thanks in Advance, Prabhu ---------- Post updated at 09:34 AM ---------- Previous update was at 05:59 AM ---------- Any one please clarify (1 Reply)
Discussion started by: prsampath
1 Replies

4. Shell Programming and Scripting

Perl map doubt

Hello , Please can someone tell me what exactly happens when the below filehandler is chomped into an array and later mapped. $lcpLog="logcopy\@".getTimestamp."\log"; open CFg ,"< $lcpcfg"; chomp(@cfg = <CFG>); close CFG; @cfg=grep { $_ ne ' ' } map { lc + (split /\s*\/\//) }... (0 Replies)
Discussion started by: rmv
0 Replies

5. Shell Programming and Scripting

csh script doubt

Hi, I need to execute output one command in csh. Eg: #!/bin/csh set smal = "set count = 1" grep "Tot" in_file | sed "s/Tot/$smal/g" In the above script, i have set the smal variale as "set count = 1". My desired output like: $echo count should show as 1. (1 Reply)
Discussion started by: vasanth.vadalur
1 Replies

6. Shell Programming and Scripting

doubt in /etc/inittab script

Hi.. When i was just looking throught /etc/inittab file.. i had stuck with some problems that i dont known in shell scripts Here how the lablel like si ca lo l1 etc works.. do scripts proivide any label features.. please help... thanks in advance esham (3 Replies)
Discussion started by: esham
3 Replies

7. Solaris

doubt regarding making a script

Hi, I want to execute around fifty commands on a server. I want to make it using a single command by placing the commands in a script. How to do this. (4 Replies)
Discussion started by: rogerben
4 Replies

8. UNIX for Advanced & Expert Users

i have a doubt with the awk script??

Hi Guys, I am new to this forum, i have doubt with a awk script. I want to generate a list where i can busiest hour from a list of a data. 05/19/2008 14:27:19 - avg: 0 max: 0 min: 0 samples: 0 total: 0 05/19/2008 14:28:19 - avg: 0 max: 0 min: 0 samples: 0 total: 0 05/19/2008 14:29:19 -... (2 Replies)
Discussion started by: asirohi
2 Replies

9. Shell Programming and Scripting

shell script doubt

Hi, While reading a shell script ,i have come accross the following statements. script_name_full=$0 ***script_name=${script_name_full##*\} ***script_name_noexst=${script_name%%\.ksh} host_name=`hostname` ***host_name_short=${host_name%%\.*} can anybody tell me what is the purpose of marked... (5 Replies)
Discussion started by: ravi raj kumar
5 Replies

10. Shell Programming and Scripting

perl doubt plz explain....

hi all i wrote a shell script which uses perl script my code is : >cat filename | while read i >do >perl -e 'require "/home/scripts/abc.pl" ; abc("$i")' >done perl script used will simply check syntax of Cobol programs but it didn't work for me so i asked my colleague he suggested... (1 Reply)
Discussion started by: zedex
1 Replies
Login or Register to Ask a Question