Sort file by day of year


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sort file by day of year
# 1  
Old 10-23-2012
Sort file by day of year

Hello,

It's a shame to not be able to do what I need, but I am sure you will :

Here is what I have in my log file :

Code:
New File: 95106 Jun 6 48 TAG__KSO__2012092_0.TAB
New File: 95106 Mar 26 48 TAG__KSM__2012020_0.TAB
New File: 95106 Mar 26 48 TAG__KSO__2012020_0.TAB
New File: 95106 May 10 48 TAG__SC___2012065_0.TAB
New File: 95106 Oct 20 48 TAG__SC___2012228_0.TAB

I am looking for sorting the file by day of the year like this :

Code:
New File: 95106 Mar 26 48 TAG__KSM__2012020_0.TAB
New File: 95106 Mar 26 48 TAG__KSO__2012020_0.TAB
New File: 95106 May 10 48 TAG__SC___2012065_0.TAB
New File: 95106 Jun 6 48 TAG__KSO__2012092_0.TAB
New File: 95106 Oct 20 48 TAG__SC___2012228_0.TAB

thanks
# 2  
Old 10-23-2012
Code:
sort -t_ -n -k 5.5,5.7 file

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 10-23-2012
@elixir - Sort with fields wont work here as position of strings are not the same and _ also not the same..

Code:
awk -F "2012" '{print $2,$0 }' file | sort -n | cut -d' ' -f2-

This User Gave Thanks to pamu For This Post:
# 4  
Old 10-23-2012
Thanks to all for your quick reply. Your code is working perfect.

Thanks ; )

If just you may time to explain, that would be great for me ...
Code:
sort -t_ -n -k 5.5,5.7

thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Julian day to dates in YEAR-MONTH-DAY

hello, I have many files called day001, day002, day003 and I want to rename them by day20070101, day20070102, etc. I need to do it for several years and leap years as well. What is the best way to do it ? Thank you. (1 Reply)
Discussion started by: Ggg
1 Replies

2. Shell Programming and Scripting

Day of year to dd.mm.yyyy format

Hi, How can I convert day of year value in format(yy,doy) to normal formatted (dd.mm.yyyy) string also all of them with awk or awk system function? in_file.txt --------- 12,043 12,044 12,045 12,046 out_file.txt ---------- 12.02.2012 13.02.2012 14.02.2012 15.02.2012 imagine... (5 Replies)
Discussion started by: kocaturk
5 Replies

3. Shell Programming and Scripting

How to extract the day of the year and use that info to copy a file remotely

Hello, Thank you in advance for helping a newbie who is having great trouble with this simple task. I'm allowed to copy one file remotely each night due to bandwidth restrictions. A new file gets generated once a day, and I need to copy the previous day's file. Here is what I'd like to do:... (1 Reply)
Discussion started by: tmozdzen
1 Replies

4. Shell Programming and Scripting

Get day of year

Hi, I wold like to know the day of year from a date in input. I know to get this from sysate with date +%j But from a date in input? :confused: Thanks (2 Replies)
Discussion started by: pinguc
2 Replies

5. Shell Programming and Scripting

Concatenating Files In A Year/Month/Day File Structure

Hi Im trying to concatenate a specific file from each day in a year/month/day folder structure using Bash or equivalent. The file structure ends up like this: 2009/01/01/products 2009/01/02/products .... 2009/12/31/products The file I need is in products everyday and I need the script to... (3 Replies)
Discussion started by: Grizzly
3 Replies

6. Shell Programming and Scripting

Day of month and year to mmddyyyy

I have a date that looks like this: 2008/100:18:40:47.040 I need it to look like this: 2008 04 09 18 40 47 040 I have looked at datecalc and it doesn't seem like it takes the day of year for this year (or whatever year is input) and converts it into month and day. It also has to account... (2 Replies)
Discussion started by: ajgwin
2 Replies
Login or Register to Ask a Question