The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: New to Unix---
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 02-13-2002
peter.herlihy peter.herlihy is offline
Registered User
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
A question for you.... are there two columns of data - or is each row considered one entry. These things are very important things to know as it is handled quite differently.

If each row if one entry....(which I doubt but here goes) - the sort function is the one you need and it is simply used in this syntax:

sort inputfile > outputfile

Now if there are indeed 2 columns - and you want all data listed into one column sorted ..... i.e

01-xdsabcd
02-xdsabce
.....

Then you need to get the data into one column to start with as the sort function will use the entire row as one entry or a number of fields within one entry - but won't separate them out.

There may be a way using just the sort function to separate the two fields per row into a single list but I don't know it.

To get the data from the original file into a single list use this (there are heaps of ways to do this i.e. awk.....):

cut -c1-'11' inputfile > outputfile
cut -c'13'-'24' inputfile >> outputfile
sort outputfile > sorted_file

(You may or may not need to put the 11, 13 and 24 into quotes depending on your system.

This basically takes the first 11 characters on a row and puts it in a file. Then takes the next 11 (after the whitespace) and apends them to the end of this file. Then sorts the file in ascending order alphanumerically.

Hope this helps.
__________________
Pete