Sponsored Content
Top Forums Shell Programming and Scripting Sort flat file by 3rd column in perl Post 302573365 by Pratik4891 on Monday 14th of November 2011 08:16:28 AM
Old 11-14-2011
You guys are absolutely correct
Here what I come up with ...I dont have any working knowledge in perl

Code:
 
#!/usr/bin/env perl
use strict;
use warnings;
my %link_strengths;
while (<>) {
chomp;
my @rec = split /\|/; 
my $key = $rec[2]; 
# my ($link, $strength) = split /\s+/;
$link_strengths{$key} = $_;
}
my @sorted = sort {
$link_strengths{$a} <=> $link_strengths{$b}
} keys %link_strengths;
for my $link (@sorted) {
print "$link: $link_strengths{$link}\n";
}

I am confused how to store the third value and also how can I use the numeric comparison operator on $a and $b 3rd field .

Please help ,if you send some url it will be of gr8 help!!!!!!!!!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Look up column in a flat file

Here is on more go ! Need a shortcut for my problem ! problem is i have a look_update with fixed sequence of column that is : MANDT:SERAIL:SERSCHA:SEREX:EQTYP:BSTVP I will be getting data in a flat file having same number of column but the sequence could be different in each... (5 Replies)
Discussion started by: jambesh
5 Replies

2. UNIX for Dummies Questions & Answers

Trim String in 3rd Column in Tab Delimited File...SED/PERL/AWK?

Hey Everybody, I am having much trouble figuring this out, as I am not really a programmer..:mad: Datafile.txt Column0 Column1 Column2 ABC DEF xxxGHI I am running using WGET on a cronjob to grab a datafile, but I need to cut the first three characters from... (6 Replies)
Discussion started by: rickdini
6 Replies

3. Shell Programming and Scripting

Converting Column to Rows in a Flat file

Hi, Request To guide me in writing a shell program for the following requirement: Example:if the Input File contains the follwing data Input File Data: 80723240029,12,323,443,88,98,7,98,67,87 80723240030,12,56,6,,,3,12,56,6,7,2,3,12,56,6,7,2,3,88,98,7,98,67,87... (5 Replies)
Discussion started by: srinikal
5 Replies

4. Shell Programming and Scripting

Flat File column manipulation

Hi All, I have a tab delimited input file with say 4 fields (columns) as below : 0000443 1AGPR061 2006 Daiml 0002198 1B3XG0K2 1989 Chdds 0002199 1Bd64J0L 1990 Ch34s 0002275 1B3s4J0K 1989 Chadys 0002276 1B465302 2002 Dageml 0002290 1B45430K 1989 Cays I want the 2nd column in file to... (5 Replies)
Discussion started by: net
5 Replies

5. Shell Programming and Scripting

How to read the first column in a flat file with ~ as delimiter

I have one flat file like below id1~col~batch1 id2~col2~batch2 id3~col3~batch3 I need to read the first column one by one and I need to write one db2 query based on that column1 Like for (i=0;i<=10;i++) do insert into table column (con_id) values (select column from table where... (4 Replies)
Discussion started by: siri_886
4 Replies

6. UNIX for Dummies Questions & Answers

Sort after 2. column in array in Perl

Hey How do I sort an array numerically after the second column? My values are integers like 1, 2, 3, 4... and they are not unique, so I can't just reverse my hash and sort by keys. I wanna sort my file/array so that I get the lines with the highest value in the top - that is descending. ... (2 Replies)
Discussion started by: Banni
2 Replies

7. Shell Programming and Scripting

Summation of column value in flat file

Hello Guys Please find my below requirement I have a flat file with column headers in first line and data The structure like below col1 col2 col3 A 1 2 B 3 4 C 5 6 Say I have to take the summation of col2 (that will depend on the... (2 Replies)
Discussion started by: Pratik4891
2 Replies

8. UNIX for Dummies Questions & Answers

sort a unix file by 3rd column

Hi, Can anybody tell me how to sort a unix file by 3rd column and not by ltr? Please help Thanks in advance (2 Replies)
Discussion started by: vinnyvirk
2 Replies

9. Shell Programming and Scripting

Sort based on positions in flat file

Hello, For example: 12........6789101112..............20212223242526..................50 ( Positions) LName FName DOB (Lastname starts from 1 to 6 , FName from 8 to 15 and date of birth from 21 to29) CURTIS KENNETH ... (5 Replies)
Discussion started by: duplicate
5 Replies

10. Shell Programming and Scripting

Solution for replacement of 4th column with 3rd column in a file using awk/sed preserving delimters

input "A","B","C,D","E","F" "S","T","U,V","W","X" "AA","BB","CC,DD","EEEE","FFF" required output: "A","B","C,D","C,D","F" "S", T","U,V","U,V","X" "AA","BB","CC,DD","CC,DD","FFF" tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
Discussion started by: khblts
5 Replies
Prophet::Web::Menu(3pm) 				User Contributed Perl Documentation				   Prophet::Web::Menu(3pm)

NAME
Prophet:Web::Menu - Handle the API for menu navigation METHODS
new PARAMHASH Creates a new Prophet::Web::Menu object. Possible keys in the PARAMHASH are "label", "parent", "sort_order", "url", and "active". See the subroutines with the respective name below for each option's use. label [STRING] Sets or returns the string that the menu item will be displayed as. parent [MENU] Gets or sets the parent Prophet::Web::Menu of this item; this defaults to null. This ensures that the reference is weakened. sort_order [NUMBER] Gets or sets the sort order of the item, as it will be displayed under the parent. This defaults to adding onto the end. link Gets or set a Jifty::Web::Link object that represents this menu item. If you're looking to do complex ajaxy things with menus, this is likely the option you want. target [STRING] Get or set the frame or pseudo-target for this link. something like _blank class [STRING] Gets or sets the CSS class the link should have in addition to the default classes. This is only used if "link" isn't specified. url Gets or sets the URL that the menu's link goes to. If the link provided is not absolute (does not start with a "/"), then is is treated as relative to it's parent's url, and made absolute. active [BOOLEAN] Gets or sets if the menu item is marked as active. Setting this cascades to all of the parents of the menu item. child KEY [, PARAMHASH] If only a KEY is provided, returns the child with that KEY. Otherwise, creates or overwrites the child with that key, passing the PARAMHASH to "new" in Jifty::Web::Menu. Additionally, the paramhash's "label" defaults to the KEY, and the "sort_order" defaults to the pre-existing child's sort order (if a "KEY" is being over- written) or the end of the list, if it is a new "KEY". active_child Returns the first active child node, or "undef" is there is none. delete KEY Removes the child with the provided KEY. children Returns the children of this menu item in sorted order; as an array in array context, or as an array reference in scalar context. render_as_menubar [PARAMHASH] Render menubar with YUI menu, suitable for an application's menu. It can support arbitary levels of submenu. as_link Return this menu item as a "Jifty::Web::Link", either the one we were initialized with or a new one made from the "/label" and "/url" If there's no "/url" and no "/link", renders just the label. perl v5.10.1 2009-12-22 Prophet::Web::Menu(3pm)
All times are GMT -4. The time now is 06:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy