Solved

Sorting in UNIX

Posted on 2001-06-21
3
299 Views
Last Modified: 2013-12-06
I'm using HP UX, kornshell.

How do you sort by position and not fields?

File to sort
file name: test.dat

Joe  sdfwere adf dsf dsf e    78323
Jack dsf asdfkj ajsd ljdf     23432
Mary asd asdfj sdfj    fsd ad 12343
Able asdf sdfjjfdljsl sdkjf   27382

I want to sort by the last 5 digits of each record.

How do I do this?

Thanks
0
Comment
Question by:waipahu
3 Comments
 
LVL 6

Accepted Solution

by:
bira earned 100 total points
Comment Utility
If the last 5 characters are aligned, you can use that:
 cat test.txt |sort -k.31,.35  
 So only the columns between 31 and 35 would be sorted.

 But if the last 5 characters are not aligned, you
 better use a C program.
0
 
LVL 8

Expert Comment

by:mnashadka
Comment Utility
If the last columns are not aligned, try something like:

cat test.txt | awk '{ print $NF" "$0}' | sort -n | awk '{ print substr($0, 7, length($0) - 6) }'
0
 

Author Comment

by:waipahu
Comment Utility
Thank you very much! It works!
Thanks also for the AWK command!
You guys are great!

Mahalo! (thank you in hawaiian)

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now