Solved

Sorting in UNIX

Posted on 2001-06-21
3
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
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.:

751 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