The UNIX and Linux Forums  

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
doubt in awk jisha Shell Programming and Scripting 4 04-16-2008 01:02 AM
AWK doubt Rafael.Buria Shell Programming and Scripting 2 02-06-2008 08:00 AM
doubt about awk soujanya_srk UNIX for Dummies Questions & Answers 2 01-10-2008 02:26 PM
awk doubt.. esham Shell Programming and Scripting 11 10-10-2007 11:24 PM
ftp doubt ranj@chn Shell Programming and Scripting 0 01-04-2006 05:47 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-01-2001
Registered User
 

Join Date: Sep 2001
Location: India.
Posts: 5
Angry awk doubt

I'm having a file with 5 fields.
I want to sort that file according to one field
no 3. How shall I do using awk programming.

Any input appreciatable.

regards,
vadivel.
__________________
vadivel.r
Reply With Quote
Forum Sponsor
  #2  
Old 10-02-2001
Registered User
 

Join Date: Oct 2001
Location: San Francisco
Posts: 27
If you are asking how to sort a file on the 5th field, that's easy:

sort -k 5 < file

I can certainly give you an example in awk too, but, be careful what you ask for.. ;-)

- dEvNuL
Reply With Quote
  #3  
Old 10-02-2001
Registered User
 

Join Date: Sep 2001
Location: India.
Posts: 5
Sort is not reliable for all fields.

Hi,

thanks for ur response. But that sort option is
not working. My file is like,

ABCD 2.03 0.00 123.00 0.00
ACB 0.00 25.00 0.00 123.23
ABVCERR[12] 0.00 456.00 98.00 0.00

like this I want to sort with the last field.
As every field is of various length and 5 spaces
between fields, I'm not able to use sort command
like sort -t\ +3rn < file
it is giving some garbage results. That's why
I want an awk program which will be a secured one.
Thanks for any input.

Regards,
vadivel.
Reply With Quote
  #4  
Old 10-02-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,614
Try "sort -k5n". I have tried it on your data and it worked for me.
Reply With Quote
  #5  
Old 10-02-2001
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,441
Remember, homework is not allowed in the forums. This looks like a homework problem to me
Reply With Quote
  #6  
Old 10-02-2001
Registered User
 

Join Date: Sep 2001
Location: India.
Posts: 5
I'm not a student.

Sorry,

I'm a programmer. I'm having the problem in
extracting a report file. I dont want to give
the exact information in the report file,
so I gave an example. If it leads to a
misunderstanding that I'm a student I feel
sorry for that.

Regards,
vadivel.
Reply With Quote
  #7  
Old 10-02-2001
Registered User
 

Join Date: Sep 2001
Location: India.
Posts: 5
Hi Perderabo,

I'm getting error message like,

sort: option requires an argument -- k

for the command sort -k5n < file
It is suggesting that I've to give end
field argument also.

regards,
vadivel
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0