sorting lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sorting lines
# 1  
Old 02-09-2005
Question sorting lines

i have another question..

i have this file:

John Jones
John Smith
Jack Smith
100100 13
Helen Bold
100200 5

how can i use sort to make it look like :

Helen Bold
John Jones
Jack Smith
John Smith
100100 13
100200 5

Surname as the major key ,firstname as the minor key and numbers at the
end.
# 2  
Old 02-10-2005
easiest way would be using sort +pos1 -pos2 ( man sort ). However, first you need to convert your file in column aligned format, so that both surname and name columns begin in known position.
# 3  
Old 02-10-2005
Quote:
Originally Posted by Phantom
easiest way would be using sort +pos1 -pos2 ( man sort ). However, first you need to convert your file in column aligned format, so that both surname and name columns begin in known position.
i've tried that ,i 've read the man pages and still i cant get the numbers to appear at the end the file ..

any other ideas?
# 4  
Old 02-10-2005
Tested on the sample data provided the following command works as expected - your milage may vary.

sort -k1n -k2 my_file

Tested...
Helen Bold
John Jones
Jack Smith
John Smith
100100 13
100200 5

Cheers
ZB
# 5  
Old 02-10-2005
MySQL

Quote:
Originally Posted by zazzybob
Tested on the sample data provided the following command works as expected - your milage may vary.

sort -k1n -k2 my_file

Tested...
Helen Bold
John Jones
Jack Smith
John Smith
100100 13
100200 5

Cheers
ZB
well done mate ...i couldnt find anything and someone proposed using grep like :
(grep -v '^[0-9]' final2 | sort -k 2,2 -k 1,1; grep '^[0-9]' final2 | sort -k 2,2 -k 1,1)
wich worked just fine but yours is much sorter and number of characters does count in my programm

thanx

Last edited by kion; 02-10-2005 at 07:27 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting block of lines based on specified strings

Below is the part of contents of a file cat outputFile.txt :APP-MS-service_monitoring-118054-DiskFilling-S Description=Disk is getting filled. If Condition=If Event/Log Level(ANY) and matching substring "DiskFilling" Log: xx.x.x..xx.: 4 days 1:33:54.42 Date and time=03-18-2013... (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

Sorting lines between patterns in alphabetical order

Hi, need help in sorting lines between strings "<section status = “ole-service”>" and "</section>" in alphabetical order, based on the text in red. Hoping for an AWK or SED solution. Thank you. ... <section status = “ole-service”>... <p service = "OOO">XZZ</p> <p service = "AAA">AAA... (3 Replies)
Discussion started by: pioavi
3 Replies

3. UNIX for Dummies Questions & Answers

Help sorting with du

Hi! As a part of a larger script I'm using the comand du -k to get the sizes of various directories, the output is printed like this: 1324 ./images/backup/2012 1333 ./images/backup 1400 ./images 22 ./video/backup 44 ./video 1450 . I'm trying to print it the other way around with... (2 Replies)
Discussion started by: Tralaraloro
2 Replies

4. Shell Programming and Scripting

Sorting lines based on keywords for MySQL script

the thing which i require is very very complex.. i tried hard to find the solution but couldnt.. the thing i need to achieve is say i have a file cat delta.sql CREATE VIEW Austin Etc etc . . . CREATE VIEW Barabara AS SELECT blah blah blah FROM Austin z, Cluster s, Instance i WHERE... (4 Replies)
Discussion started by: vivek d r
4 Replies

5. Shell Programming and Scripting

sorting based on alternative lines

Hello, I have a file with multiple entries. @SFGF-GA2-1_58:5:36:11009:999#0/1 NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN +SFGF-GA2-1_58:5:36:11009:999#0/1 ################################################################################... (10 Replies)
Discussion started by: Diya123
10 Replies

6. Shell Programming and Scripting

sorting

Hii guys, I need to sort my file and remove duplicates before writing to another file. The first line in the file are column names. I dont want this line to be sorted and should always be the first line in the output. sort -u file.txt > file1.txt. is the command that i am using... (4 Replies)
Discussion started by: just4u_sharath
4 Replies

7. Shell Programming and Scripting

Sorting HELP

Hi, I have posted related topic but as i continue the research I find more need to sort the data. AS(2607:f278:4101:11:dead:beef:f00f:f), AS786 AS6453 AS7575 AS7922 AS(2607:f2e0:f:1db::16), AS786 AS3257 AS36252 AS786 AS3257 AS36252 AS(2607:f2f8:1700::2), AS786 AS6939 AS25795 ... (6 Replies)
Discussion started by: sam127
6 Replies

8. Shell Programming and Scripting

Need immediate help with sorting!!!

hey, I have a file that looks smthng like this: /*--- abcd_0050 ---*/ asdfjk adsfkja lkjljgafsd /*---abcd_0005 ---*/ lkjkljbfkgj ldfksjgf dfkgfjb /*-- abcd_0055--*/ klhfdghd dflkjgd jfdg I would like it to be sorted so that it looks like this: /*---abcd_0005 ---*/ lkjkljbfkgj (9 Replies)
Discussion started by: sasuke_uchiha
9 Replies

9. UNIX for Dummies Questions & Answers

How to count lines - ignoring blank lines and commented lines

What is the command to count lines in a files, but ignore blank lines and commented lines? I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end. Here is an example of what I would like my... (6 Replies)
Discussion started by: kthatch
6 Replies

10. UNIX for Advanced & Expert Users

Horizontal sorting of lines in a File: SED implementation?

Hi guys, Do you know how can I sort a file horizontally per line??? sample input file: zebra papa dog apple yahoo kangaroo ape sample output: apple dog papa zebra ape kangaroo yahoo Please post if u know the sed implementation of this (or whatever implementation u may know of)... (7 Replies)
Discussion started by: marlonus999
7 Replies
Login or Register to Ask a Question