![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding specific text and spaces to each line in a text file | hertingm | Shell Programming and Scripting | 4 | 08-25-2008 11:34 AM |
| Building Full-Text Search Applications with Oracle Text | iBot | Oracle Updates (RSS) | 0 | 04-06-2008 02:10 AM |
| Perl Sort on Text File | eltinator | Shell Programming and Scripting | 6 | 08-07-2007 11:20 AM |
| Need a Help with sort a text file with some fields | alexcol | Shell Programming and Scripting | 3 | 02-19-2007 12:13 AM |
| grep multiple text files in folder into 1 text file? | coppertone | UNIX for Dummies Questions & Answers | 7 | 08-23-2002 11:50 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sort Text
Hello,
I have a text file that I need to sort the lines by date record=5,French 9,2008-09-02T08:55:00,2008-09-02T10:00:00,2 record=79,Entrepreneurship 30,2008-09-17T11:00:00,2008-09-17T12:00:00,2 record=6,Computer Science 20,2008-09-02T09:55:00,2008-09-02T10:50:00,1 record=7,Entrepreneurship 30,2008-09-02T11:00:00,2008-09-02T12:00:00,2 Essentially I need to sort these lines by the start date & time which is bolded here. Is it possible to sort these lines by the date highlighted? Thank you for your help Dallas |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Try this:
Code:
awk -F, '{t=$3;gsub("[-T:]*","",t);print t,$0}' inputfile | sort -n -k 1,1 | cut -d " " -f 2- > outputfile
|
|
#3
|
|||
|
|||
|
I have to be honest with you. I have absolutely no idea how this works but it works very well. Thank you so much for your help.
Thank you Annihilannic Dallas |
|
#4
|
|||
|
|||
|
Hello,
Based in this same text format is there a way to extract all lines between two dates. record=5,French 9,2008-09-05T08:55:00,2008-09-02T10:00:00,2 record=79,Entrepreneurship 30,2008-09-04T11:00:00,2008-09-17T12:00:00,2 record=6,Computer Science 20,2008-09-03T09:55:00,2008-09-02T10:50:00,1 record=7,Entrepreneurship 30,2008-09-02T11:00:00,2008-09-02T12:00:00,2 Essentially can I pull say the all items between September 3 at midnight and september 4th at midnight. Thank you Dallas |
|
#5
|
|||
|
|||
|
Try this:
Code:
awk -F, '{t=$3;gsub("[-T:]*","",t); if (t >= 20080903000000 && t < 20080904000000) print t,$0}' inputfile | sort -n -k 1,1 | cut -d " " -f 2- > outputfile
awk -F, - run awk, setting the default input field separator to a comma. The next part between the single quotes is the awk script: {t=$3; - assign the third field to variable "t" gsub("[-T:]*","",t); - substitute any occurrences of dash, capital T or a colon in the variable "t" with nothing if (t >= 20080903000000 && t< 20080904000000) print t,$0} - print t followed by the original input line only if the timestamp is in the specified range inputfile - the input data | sort -n -k 1,1 - sort numerically by the first field | cut -d " " -f 2 - remove the temporary first field which we used for sorting > outputfile - and store the output in "outputfile" |
|
#6
|
|||
|
|||
|
Thanks again, I really appreciate your help. I have been working on a custom scheduling software for an in house project at my work and your help with processing this data has really sped up my progress. Thank you
Dallas |
|||
| Google The UNIX and Linux Forums |