Solved

Sorting in UNIX

Posted on 2001-06-21
3
302 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
ID: 6216447
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
ID: 6216453
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
ID: 6216572
Thank you very much! It works!
Thanks also for the AWK command!
You guys are great!

Mahalo! (thank you in hawaiian)

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

895 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

16 Experts available now in Live!

Get 1:1 Help Now