Sort the multi column rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort the multi column rows
# 1  
Old 07-09-2010
Sort the multi column rows

Code:
abc       [5/Jul/2010:00:59:59    +0000]
xyz    [5/Jul/2010:00:10:00    +0000]
-    [5/Jul/2010:06:10:00    +0000]
-    [5/Jul/2010:06:50:00    +0000]
-    [5/Jul/2010:07:10:00    +0000]
-    [5/Jul/2010:10:10:00    +0000]
-    [6/Jul/2010:06:10:00    +0000]
-    [6/Jul/2010:07:10:00    +0000]
-    [5/Jul/2010:08:10:00    +0000]
-    [5/Jul/2010:06:10:00    +0000]
-    [5/Jul/2010:09:10:00    +0000]
-    [5/Jul/2010:10:00:00    +0000]
-    [5/Jul/2010:10:15:00    +0000]

How to sort the second column in ascending order.
# 2  
Old 07-09-2010
from second column, do you mean this "[5/Jul/2010:00:59:59" ??

Code:
$ sort -k2 file
abc       [5/Jul/2010:00:59:59    +0000]
xyz    [5/Jul/2010:00:10:00    +0000]
-    [5/Jul/2010:06:10:00    +0000]
-    [5/Jul/2010:06:10:00    +0000]
-    [5/Jul/2010:06:50:00    +0000]
-    [5/Jul/2010:07:10:00    +0000]
-    [5/Jul/2010:08:10:00    +0000]
-    [5/Jul/2010:09:10:00    +0000]
-    [5/Jul/2010:10:00:00    +0000]
-    [5/Jul/2010:10:10:00    +0000]
-    [5/Jul/2010:10:15:00    +0000]
-    [6/Jul/2010:06:10:00    +0000]
-    [6/Jul/2010:07:10:00    +0000]
$

you can provide many options in sort, if this is not the case, please provide the expected output.
# 3  
Old 07-11-2010
If the days of the month in your file were all two digits (padded with 0 if necessary), then this example in the info page of GNU sort can help:

Code:
   * Sort a set of log files, primarily by IPv4 address and secondarily
     by time stamp.  If two lines' primary and secondary keys are
     identical, output the lines in the same order that they were
     input.  The log files contain lines that look like this:

          4.150.156.3 - - [01/Apr/2004:06:31:51 +0000] message 1
          211.24.3.231 - - [24/Apr/2004:20:17:39 +0000] message 2

     Fields are separated by exactly one space.  Sort IPv4 addresses
     lexicographically, e.g., 212.61.52.2 sorts before 212.129.233.201
     because 61 is less than 129.

          sort -s -t ' ' -k 4.9n -k 4.5M -k 4.2n -k 4.14,4.21 file*.log |
          sort -s -t '.' -k 1,1n -k 2,2n -k 3,3n -k 4,4n

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

DB2 Query -Convert multi values from column to rows

Hi Team I am using DB2 artisan tool and struck to handle multi values present in columns that are comma(,) separated. I want to convert those column values in separate rows . For example : Column 1 Column2 Jan,Feb Hold,Sell,Buy Expected Result Column1 ... (3 Replies)
Discussion started by: Perlbaby
3 Replies

2. UNIX for Dummies Questions & Answers

Egrep multi rows

I have file input input.txt 20140730|13|TORONTO|Pavja|13127|Moto|0|1568|2035|-467|59478|352450|2014-08-11 23:12:15 20140730|13|TORONTO|Pavja|13127|Manual|0|696|742|-46|38826|141449|2014-08-11 23:12:15 20140730|13|TORONTO|Pavja|13127|Semimanual|0|0|3|-3|0|317|2014-08-11 23:12:15... (6 Replies)
Discussion started by: radius
6 Replies

3. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Deleting all rows where the first column equals the second column

Hi, I have a tab delimited text file where the first two columns equal numbers. I want to delete all rows where the value in the first column equals the second column. How do I go about doing that? Thanks! Input: 1 1 ABC DEF 2 2 IJK LMN 1 2 ZYX OPW Output: 1 2 ZYX OPW (2 Replies)
Discussion started by: evelibertine
2 Replies

5. Shell Programming and Scripting

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -... (4 Replies)
Discussion started by: nricardo
4 Replies

6. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 Replies

7. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

8. UNIX for Dummies Questions & Answers

Alphabetical sort for multi line records contains in a single file

Hi all, I So, I've got a monster text document comprising a list of various company names and associated info just in a long list one after another. I need to sort them alphabetically by name... The text document looks like this: Company Name: the_first_company's_name_here Address:... (2 Replies)
Discussion started by: quee1763
2 Replies

9. UNIX for Dummies Questions & Answers

Sort on multi columns

Hope someone can help, I am trying to sort a generic file like this test2 A 468 0 test2 R 468 1 test2 E 468 1 test2 R 468 3 test2 R 468 4 test2 R 468 459 test2 Z 468 0 test1 A 191 0 test1 R 191 191 test1 Z 191 0 test3 A 3 0 test3 R 3 3 test3 Z 3 0 test0 A 1 0 test4 A 1 0 test4 E... (2 Replies)
Discussion started by: gio001
2 Replies

10. UNIX for Dummies Questions & Answers

find and remove rows from file where multi occurrences of character found

I have a '~' delimited file of 6 - 7 million rows. Each row should contain 13 columns delimited by 12 ~'s. Where there are 13 tildes, the row needs to be removed. Each row contains alphanumeric data and occasionally a ~ ends up in a descriptive field and therefore acts as a delimiter, resulting in... (1 Reply)
Discussion started by: kpd
1 Replies
Login or Register to Ask a Question