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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Multiple file needed with certain file_prefix rauphelhunter Shell Programming and Scripting 6 05-27-2008 05:26 AM
Help Needed : Split one big file to multiple files monicasgupta Shell Programming and Scripting 5 03-03-2008 07:09 PM
add columns from file to another and sort kamel.seg Shell Programming and Scripting 12 12-12-2007 02:39 PM
Help needed to sort file inditopgun Shell Programming and Scripting 2 09-27-2007 06:40 PM
sorting a file with multiple columns outtacontrol UNIX for Dummies Questions & Answers 3 07-26-2006 01:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-04-2007
ahjiefreak ahjiefreak is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 132
Help needed to sort multiple columns in one file

Hi,

I would like to know given that I have 3 columns.

Let say I have first 3 columns to do operation and these operation output is printed out each line by line using AWK and associative array.Currently in the output file, I do a sort by -r for the operation output.

The problem comes to picture where I have more than one operation to perform on the same 3 columns and hence, different variables array.
I would like to sort this when the first and second column value gives me 0 value.

my current code is something like:-

cat a.txt| awk `
{

count[$1]=count[$3]+2;
add[$1]=count[$3]+3;
}

END{
for(i in count){
printf("%d %d\n", count[i], add[i]);}

}`|sort -r catsort.txt

The above script only sort by "count" array variables. What I desired is to have "add" to sort if $1 and $2 is "0". I thought of duplicate the whole thing again to sort by "add" which i just need to modify the printf to
printf("%d %d\n" ,add[i],count[i]) and add the condition of if $1 and $2 is 0.But it doesnt seem to make sense to me as this cause to create more files! Please help!


Thanks

-Jason
  #2 (permalink)  
Old 12-07-2007
hcliff hcliff is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 13
show me the example input and desired output

If you show me the example input data and desired output data.
It may be helpful
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 10:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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