The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
doubt in /etc/inittab script esham Shell Programming and Scripting 3 04-17-2009 12:38 PM
i have a doubt with the awk script?? asirohi UNIX for Advanced & Expert Users 2 07-01-2008 10:19 PM
shell script doubt ravi raj kumar Shell Programming and Scripting 5 12-05-2007 05:16 AM
colors in BASH, doubt with script jaduks Shell Programming and Scripting 4 11-19-2007 05:21 AM
perl doubt plz explain.... zedex Shell Programming and Scripting 1 09-03-2007 03:14 AM

View Poll Results: Perl
Learn 0 0%
Continuous practice 1 50.00%
Achieve 0 0%
Go ahead 1 50.00%
Voters: 2. You may not vote on this poll

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-06-2008
vasanth.vadalur vasanth.vadalur is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 23
Arrow 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 (permalink)  
Old 10-06-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 (permalink)  
Old 10-06-2008
vasanth.vadalur vasanth.vadalur is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 23
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 View Post
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 (permalink)  
Old 10-06-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.

http://www.unix.com/cfmgoogle.php?cx...sa=Search#1061
  #5 (permalink)  
Old 10-06-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,617
I have closed the poll. I see no purpose it serves.

bakunin
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0