The UNIX and Linux Forums  

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
Regarding sorting vivek.bharadwaj Shell Programming and Scripting 6 02-06-2009 02:59 AM
Need immediate help with sorting!!! sasuke_uchiha Shell Programming and Scripting 9 08-06-2008 12:07 AM
Sorting in C++.. ronix007 High Level Programming 6 03-06-2008 05:16 PM
Unix Arithmatic operation issue , datatype issue thambi Shell Programming and Scripting 23 02-19-2008 07:19 AM
Sorting mp3 penguin-friend Shell Programming and Scripting 3 05-13-2005 04:21 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-19-2009
mraghunandanan mraghunandanan is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 38
Sorting Issue

Hi Guys,

I am very new to Unix.Can anyone tell me how to sort a file based on fields.

For example, I am having a file whose contents are mentioned below:

2233|charles harris |g.m. |sales |12/12/52| 90000 9876|bill johnson |director |production|03/12/50|130000 5678|robert dylan |d.g.m. |marketing |04/19/43| 85000 2365|john woodcock |director |personnel |05/11/47|120000 Each line contains emp-id, name, designation, department, date of birth, and salary.

How to sort the file on the basis of salary?
How to get unique designations?

Regards,

Mahesh Raghunandanan
  #2 (permalink)  
Old 03-19-2009
JerryHone JerryHone is offline
Registered User
  
 

Join Date: Nov 2006
Location: UK
Posts: 178
Type
Code:
man sort
to get the sort manual which describes sorting by columns.
But to be brutally honest, the easiest way is to open the file in Excel (other spreadsheets will do!), split the columns and hit the Sort menu option!
  #3 (permalink)  
Old 03-19-2009
borderblaster borderblaster is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 48
sort -t "|" -k 6 -n -r sortsalary.txt
9876|bill johnson |director |production|03/12/50|130000
2365|john woodcock |director |personnel |05/11/47|120000
2233|charles harris |g.m. |sales |12/12/52|90000
5678|robert dylan |d.g.m. |marketing |04/19/43|85000
  #4 (permalink)  
Old 03-19-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
Code:
sort -t"|" -n -r +5 filename
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 08:24 AM.


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