1833873 Members
2081 Online
110063 Solutions
New Discussion

sorting

 
SOLVED
Go to solution
andi_1
Frequent Advisor

sorting

Hi guys,

For example, I have the following file:

/dev/vg00,/dev/vg00/lvol1,0,25,0,0,0,22,2,100
/dev/vg00,/dev/vg00/lvol2,0,256,0,,0,0,2,1024
/dev/vg00,/dev/vg00/lvol3,0,38,0,0,1,1,2,152
/dev/vg00,/dev/vg00/lvol4,0,25,0,0,0,0,0,100

I'd like to sort the above lines by # of stripes. It is field #8. (where you see 22)

What is the best way to sort the above file, so I have no striped lvol (0) first followed by stripped ones?>

Thank you!
8 REPLIES 8
Bill Hassell
Honored Contributor

Re: sorting

man sort

sort -t, -k8

You can reverse the order with -r. -k is the field number (-k2 sorts by lvol)


Bill Hassell, sysadmin
Mark Greene_1
Honored Contributor

Re: sorting

try this:

sort -t , -k 8 [filename]

HTH
mark
the future will be a lot like now, only later
S.K. Chan
Honored Contributor

Re: sorting

# sort -t, -k8
andi_1
Frequent Advisor

Re: sorting

Hi guys,

Here is my original file:

1 2 /dev/vg00 /dev/vg00/lvol2 0 256 0 0 0 1 2 1024
1 09 /dev/vgsys /dev/vgsys/lvm 0 125 0 25 0 0 0 1000
1 10 /dev/vgsys /dev/vgsys/lvk 0 125 0 0 0 0 0 1000
1 11 /dev/vgsys /dev/vgsys/lvp 0 125 0 4 0 0 0 1000
1 12 /dev/vgsys /dev/vgsys/lvs 0 125 0 0 0 0 0 1000
1 13 /dev/vgsys /dev/vgsys/lvu 0 50 0 4 0 0 0 400

# sort -t, -r k 8 tmp > tmpSorted

Here is sorted output:
1 13 /dev/vgsys /dev/vgsys/lvu 0 50 0 4 0 0 0 400
1 12 /dev/vgsys /dev/vgsys/lvs 0 125 0 0 0 0 0 1000
1 11 /dev/vgsys /dev/vgsys/lvp 0 125 0 4 0 0 0 1000
1 10 /dev/vgsys /dev/vgsys/lvk 0 125 0 0 0 0 0 1000
1 09 /dev/vgsys /dev/vgsys/lvm 0 125 0 25 0 0 0 1000
1 02 /dev/vg00 /dev/vg00/lvol2 0 256 0 0 0 1 2 1024

Doesn't seem to sort?

Any ideas why?

Thank you!
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: sorting

Hi:

Your original posting had comma's as field separators (hence the -t, argument). You new original file does not have comma's. That is why sort is 'not' working.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: sorting

Hi Leon:

Your representation of the data originally showed the field delimiter being a comma (',') and hence the '-t,' option was specified to 'sort'. Therefore, if you input is comma delimited, use '-t,' but if it is space delimited as you show, drop the '-t,' option from the sort specification.

Regards!

...JRF...
Helen French
Honored Contributor

Re: sorting

Hi Leon,

As Clay suggested, the -t is used to specify the 'character' in the input file.

If you don't have the ',' in the file, then use:

# sort -r -k3 file_name

If you don't use -t it will assume the 'character' as blank.

HTH,
Shiju
Life is a promise, fulfill it!
Helen French
Honored Contributor

Re: sorting

oops ..it should be:

# sort -r -k8 tmp > tmpsorted

HTH,
Shiju

Life is a promise, fulfill it!