05-12-2009
Vn
1705614|FNP|2|99|U|1/20/2009 0:00:00
1705614|MSN|1|99|C|1/2/2009 0:00:00
I want the above data to be sorted based on 0 / 4 / 3 / 2 fields (assume above data in abc.txt file)
sort -t '|' +0n +4 +3n +2nr abc.txt
1705614|MSN|1|99|C|1/2/2009 0:00:00
1705614|FNP|2|99|U|1/20/2009 0:00:00
in case my 4 and 3 fields are same I want to sort by field 2 in descending order, that means if the data is
1705614|MSN|1|99|C|1/2/2009 0:00:00
1705614|FNP|2|99|C|1/20/2009 0:00:00
I want this to be flipped like
1705614|FNP|2|99|C|1/20/2009 0:00:00
1705614|MSN|1|99|C|1/2/2009 0:00:00
with the above sort command it doesn't work...please help
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have an urgent task here. I am required to sort a flat file based on multiple columns which are based on the character position in that line. I am restricted to use the character position instead of the space and sort +1 +2 etc to do the sorting.
I understand that there is a previous... (8 Replies)
Discussion started by: cucubird
8 Replies
2. UNIX for Dummies Questions & Answers
I have a file with several columns:
Column1 Column2 Column3. . .Column6
I want to sort the data from Column6. Could I do that through sort even if there are spaces in between fields?
Much thanks!
outta. (3 Replies)
Discussion started by: outtacontrol
3 Replies
3. UNIX for Advanced & Expert Users
Hi all
I have data in following format:
CSCH74,2007,1,09103,15
CSCH74,2007,10,09103,0
CSCH74,2007,11,09103,0
CSCH74,2007,12,09103,0
CSCH74,2007,2,09103,15
CSCH74,2007,3,09103,194
CSCH74,2007,4,09103,115
CSCH74,2007,5,09103,66
CSCH74,2007,6,09103,0
CSCH74,2007,7,09103,0... (2 Replies)
Discussion started by: sumeet
2 Replies
4. Shell Programming and Scripting
Hi,
I want a list of entries in 3 space delimited columns. I want to sort entries based on the very first column. Rows can't be changed. For example:
If I have...
Abc Abc Acc
Bca Bda Bdd
Cab Cab Cbc
Dbc Dca Dda
Abc Abc Acc
the output should be...
Abc Abc Acc
Abc Abc Acc
Bca... (7 Replies)
Discussion started by: MobileUser
7 Replies
5. Shell Programming and Scripting
Hi gang.
I'm using a unix/mac system and i'm trying to sort a file (more than 1,000,000 lines).
chr1 100000965 100001001 -
chr1 100002155 100002191 +
chr1 100002165 100002201 +
chr1 100002525 100002561 -
chr1 10000364 ... (2 Replies)
Discussion started by: labrazil
2 Replies
6. Shell Programming and Scripting
Hi,
We have a requirement of need to sort a file based on fields 1,3 and 4. I tried with sort command however it is not giving expected output, can we achieve any other way? Please let me know ASAP.
File
a e w a
a b a a
a a d g
a a h h
c d a e
a a a w
Output
a b a a
a a a w
a a d... (4 Replies)
Discussion started by: Nagapandi
4 Replies
7. Shell Programming and Scripting
Hello,
I have data where words are separated by a delimiter. In this case "="
The number of delimiters in a line can vary from 4to 8. The norm is 4.
Is it possible to have a script where the file could be separated starting with highest number of delimiters and ending with the lowest
An... (8 Replies)
Discussion started by: gimley
8 Replies
8. UNIX for Dummies Questions & Answers
I have a space delimited text file that I would like to sort by multiple columns. First I want to sort by column 1, then by column 2. Both columns are numerical. Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies
9. UNIX for Dummies Questions & Answers
Hi
I have a text file that has four columns (Logonid,First Name,Last Name,Status)
Logonid First Name Last Name Status
abc2 Fred Mercury Inactive
abc1 John Deacon Active
abc3 Roger Taylor Active
abc4 Brian ... (2 Replies)
Discussion started by: theref
2 Replies
10. Shell Programming and Scripting
Hello all,
I am using printf to print the sorted o/p in my script.I am trying to sort in following way but doesn't work.
printf "%13s %2s UDP %15s:%s Program %4s HD: %23s HD: %23s %10s %s %s %3s days %3s hours\n" $encoder $i "${ipaddr}" ${portno} ${progno} ${inres} ${outres} ${inrate}... (4 Replies)
Discussion started by: ramman
4 Replies