sort issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sort issue
# 1  
Old 06-05-2009
sort issue

Hi Guys ,

Please help me I am having a requirement as below:

$ ls -i log* | head
66486532 log1
66486662 log10
66486663 log11
66486664 log12
66486665 log13
66486533 log2
66486534 log3
66486535 log4
66486584 log5
66486590 log6

This id listing the first 10 files starting with log.

$ ls -i log* | sort -t' ' -k1 -n |head
66486532 log1
66486533 log2
66486534 log3
66486535 log4
66486584 log5
66486590 log6
66486655 log7
66486656 log8
66486661 log9
66486662 log10

I sorted on inode numbers and got the listing.

My doubt is whether can I sort on the number after log? I am unable to find a command for it.

Please help me guys.

Regards,

Mahesh..
# 2  
Old 06-05-2009
Code:
nawk '{match($2, "[0-9]+$"); print substr($2, RSTART), $0}' myFile.txt | sort -n -k1,1 | cut -d' ' -f2-

# 3  
Old 06-05-2009
Hi..

Actually the thing is like, I want the output in such a way that the second field that contains all logfiles should be sorted and it should be printed along with the inode numbers instead of sorting first field that is inode numbers.
like

log1
log2
log3
log4
log5
log6
log7
log8
log9
log10
# 4  
Old 06-05-2009
Have you tried the X option for the ls?
# 5  
Old 06-07-2009
Quote:
Originally Posted by mraghunandanan
Hi..

Actually the thing is like, I want the output in such a way that the second field that contains all logfiles should be sorted and it should be printed along with the inode numbers instead of sorting first field that is inode numbers.
like

log1
log2
log3
log4
log5
log6
log7
log8
log9
log10
Actually.... have you tried what'd been posted?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Difference of Sort -n -k2 -k3 & Sort -n -k2,3

Hi, Could anyone kindly show me a link or explain the difference between sort -n -k2 -k3 & sort -n -k2,3 Also, if I like to remove the row with repetition at both $2 and $3, Can I safely use sort -u -k2 -k3 Example; 100 20 30 100 20 30 So, both $2 and $3 are same and I... (2 Replies)
Discussion started by: Indra2011
2 Replies

2. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

3. Shell Programming and Scripting

Help with sort word and general numeric sort at the same time

Input file: 100%ABC2 3.44E-12 USA A2M%H02579 0E0 UK 100%ABC2 5.34E-8 UK 100%ABC2 3.25E-12 USA A2M%H02579 5E-45 UK Output file: 100%ABC2 3.44E-12 USA 100%ABC2 3.25E-12 USA 100%ABC2 5.34E-8 UK A2M%H02579 0E0 UK A2M%H02579 5E-45 UK Code try: sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies

4. Shell Programming and Scripting

Alternate to sort --random-sort

sort --random-sort The full command is path=`find /testdir -maxdepth 1 -mindepth 1 -type d | ***Some sort of sort function*** | head -1` I have a list I want to randomly sort. It works fine in ubuntu but on a 'osx lion' sort dosen't have the --random-sort option. I don't want to... (5 Replies)
Discussion started by: digitalviking
5 Replies

5. Shell Programming and Scripting

Issue with Sort in Unix

Hi All, I am trying to sort the below data using sort command. temp.dat H|S1-511091486889|27-Jul-2011 00:00:00 H|S1-511091486823|27-Jul-2011 00:00:00 H|S1-511091486757|27-Jul-2011 00:00:00 L|S1-511091486889|1 L|S1-511091486823|1 L|S1-511091486757|1 sort -t "|" -k2 -k1 temp.dat My... (5 Replies)
Discussion started by: deepaknbk
5 Replies

6. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

7. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

8. Shell Programming and Scripting

Sort Issue

these are two records(adr.txt)trying to sort with the the code expl below. 5423|336110|2730 Pierce St|Ste 300|Sioux City|IA|Woodbury|51104|3765||42518651|96405013|A|2|3|U|12/08/2009 5423|14462335|624 JONES ST|STE 5400|Sioux City|IA|Woodbury|51101|||42496648|96400644|A|8|2|U |12/24/2009 nawk... (3 Replies)
Discussion started by: greenworld
3 Replies

9. Shell Programming and Scripting

sort date issue

Hi Everyone, # cat b Sat 12 Sep 2009 10:31:49 PM MYT;a;a;a;Sun 13 Sep 2009 11:32:49 AM MYT; Sat 13 Sep 2009 10:31:49 PM MYT;a;a;a;Mon 14 Sep 2009 10:31:49 PM MYT; Sat 14 Sep 2009 10:31:49 PM MYT;a;a;a;Sun 13 Sep 2009 10:31:49 PM MYT; # sort -t';' -k5 b Sat 13 Sep 2009 10:31:49 PM... (8 Replies)
Discussion started by: jimmy_y
8 Replies

10. Shell Programming and Scripting

performance issue using gzcat, awk and sort

hi all, I was able to do a script to gather a few files and sort them. here it is: #!/usr/bin/ksh ls *mainFile* |cut -c20-21 | sort > temp set -A line_array i=0 file_name='temp' while read file_line do line_array=${file_line} let i=${i}+1 (5 Replies)
Discussion started by: naoseionome
5 Replies
Login or Register to Ask a Question