Visit Our UNIX and Linux User Community

using Unix sort command

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers using Unix sort command
# 1  
Old 10-17-2009
using Unix sort command

Hi I am having some difficulties with the UNIX sort command.

I want to sort one a file that looks like this (file A):

tiger  5  6  3  5  2
bear  4  5  2  1  8
lions  9  2  5  3  1
dogs  8  5  3  3  1

acccording to a file that looks like this (file B):


So if I sort file A according to B then the output (file C) will look like this:

dogs  8  5  3  3  1
lions  9  2  5  3  1
tiger  5  6  3  5  2
bear  4  5  2  1  8

# 2  
Old 10-17-2009
awk 'NR==FNR {A[$1]=$0; next} {print A[$1]}' fileA fileB

# 3  
Old 10-17-2009
hey does not work, it just prints fileB out again (same order).

---------- Post updated at 04:00 PM ---------- Previous update was at 03:51 PM ----------

nvm it actually works. I made a mistake with something else

thank you so much!!

Previous Thread | Next Thread
Test Your Knowledge in Computers #537
Difficulty: Medium
An enumerated data type allows a user to define a list of keywords associated with integers.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX sort

Hi I have below pattern A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: pens 4 B:Bags 4 A: cells 6 A: jobs 6 Output I need : A: Apple 2 B:Bolls 4 total_count = 6 A: pens 4 B:Bags 4 total count = 8 A: cells 6 A: jobs 6 ... (7 Replies)
Discussion started by: pkkanduk
7 Replies

2. Linux

sort command in centos unix

Iam working in centos linux operating system. Consider the following file by name emp 1008 Vijay 40 1009 Rekha 34 1010 Shreyas 40 1011 Sanjay 40 sort command is not working. I gave sort emp The command is not working Can somebody send the options under centos linux (1 Reply)
Discussion started by: jpachar
1 Replies

3. Shell Programming and Scripting

Help to sort out... Possible use of sort command

I have an input like (5 Replies)
Discussion started by: dnam9917
5 Replies

4. UNIX for Dummies Questions & Answers

New to Unix command line and have a question about the "sort" command

I am going through the Unix Made Easy second edition book by John Muster. So far it's been very informative and I can tell it may be a bit out of date. In one of the exercises it talks about the "sort" command and using it to sort column's of data etc. The "sort" command has changed a bit and... (1 Reply)
Discussion started by: budfoxcat
1 Replies

5. UNIX for Advanced & Expert Users

Sort command using unix

Hello, I have a file with 'tab' separated columns. The first column of the file contains integer values. Now I want to sort the first column in ascending order. Can someone help me on this... thanks in advance (1 Reply)
Discussion started by: koneru_18
1 Replies

6. Shell Programming and Scripting

Is it Possible to sort a list of hexadecimal numbers using "sort" command?

Hello Everybody :) !!!. i have question in mind, is it possible to sort a list of hexadecimal numbers using "sort" command? (9 Replies)
Discussion started by: Kesavan
9 Replies

7. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

8. UNIX for Dummies Questions & Answers

UNIX sort command

Need some help with the sort command. I have a large file which needs sorted on the third field separated by : and within the third field, I need it sorted by second field or everything after the . An example of my file is here and for example, the first line I need :ROUTER2.SFLDMI: sorted on the... (2 Replies)
Discussion started by: numele
2 Replies

9. Shell Programming and Scripting

File size limitation of unix sort command.

hi , iam trying to sort millions of records which is delimited and i cant able to use sort command more than 60 million..if i try to do so i got an message stating that "File size limit exceeded",Is there any file size limit for using sort command.. How can i solve this problem. thanks ... (7 Replies)
Discussion started by: cskumar
7 Replies

Featured Tech Videos