nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Sorting individual records in a file based on some fields

This is a discussion on Sorting individual records in a file based on some fields within the Shell scripting forums, part of the Development/Scripting category; Hi, I am a newbie to shell scripting. I am tasked to sort a file based on some fields. For ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 07-24-2006, 02:10 PM
Junior Member
 
Join Date: Jul 2006
Posts: 1
Rep Power: 0
cucu81
Default Sorting individual records in a file based on some fields

Hi,

I am a newbie to shell scripting. I am tasked to sort a file based on some fields.

For example:

(1) (2) (3)
Japan 20 Air
Malaysia 21 Land

I will need to sort the 2 records within the file test.txt based on field(1) first and then field(2). This is similar to SQL where we order by (1),(2)

Can someone advise me on how to do that using shell scripting or awk? Its very urgent. thanks a million in advance
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-25-2006, 04:08 AM
chimu's Avatar
Contributors
User
 
Join Date: Mar 2005
My distro: Ubuntu
Posts: 33
Rep Power: 0
chimu is an unknown quantity at this point
Default

Use sort command:

Code:
sort -k +1,+2  /path/to/file
if you are using old UNIX version try
Code:
sort +1 +2 /path/to/file
read man page of sort for more
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

Similar Threads

Thread Thread Starter Forum Replies Last Post
How to match two fields Prahlad Shell scripting 3 04-09-2008 01:58 PM
need help to install FreeBSD 6 series on my Intel based pc sneezycrazyturtle All about FreeBSD/OpenBSD/NetBSD 1 02-22-2007 03:27 PM
script finding file and sorting dementeddude Shell scripting 14 07-25-2006 06:30 PM
Apache multiple IP based domains and one certificate tom All about FreeBSD/OpenBSD/NetBSD 1 06-26-2006 08:23 PM
moving files based on size kavi Shell scripting 2 11-11-2005 06:17 PM


All times are GMT +5.5. The time now is 07:15 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36