HELP: I need to sort a text file in an uncommon manner, can't get desired results
Hi All
I have a flat text file. Each line in it contains a "/full path/filename". The last three columns are predictable, but directory depth of each line varies.
I want to sort on the last three columns, starting from the last, 2nd last and 3rd last. In that order. The last three columns have a constant column width:
Last col(6): 24h time 0000.Z -> 2300.Z (compressed file)
2nd Last col(3}: Day of Year, 001 -> 365 (366 in leap years)
3rd Last col(4): Year
I'll explain with an example:
- desired sort key: last col, 2nd last col, 3rd last col
Example: (unsorted)
As you can see, the number of columns in this example vary, however, regardless the number of columns, I would like to sort the lines based on last, 2nd last & 3rd last columns, the results should look like this:
Perhaps an awk + sort command line combo will do the trick, but I'm Google'd out on searching for an answer.
Any help would be greatly appreciated.
Tks,
Jake.
Last edited by pludi; 11-04-2009 at 12:04 PM..
Reason: code tags, please...
Awesome, that did it. I keep forgetting the valuable magic (and complexity) of perl.
A thousand thank-you's.
J.
Scrutinizer:
The 'sed' command example did sort from low day of year to highest in each sub-directory. However, I blame my poor wording of my original question. What I needed in the output was a total sort of all file names in a quasi-chronological order (based on filename), oldest first so the output would contain the oldest files, regardless of subdirectory depth, at the top of the file.
Thank you very much for your answer!
J.
Last edited by JakeKatz; 11-04-2009 at 01:00 PM..
Reason: Clarifying my answer
Hello.
The task :
Using multiple commands like :
gdisk -l $SOME_DISK >> $SOME_FILEI generate some text file.
For readiness I must insert page break.
When the program is finished I want to convert the final text file to a pdf file.
When finished, I got two files : One text file and One pdf... (1 Reply)
Hi,
I had generated a report in my tool as followsoutput.txt
43.35
9
i needed the script to generate a new file like below
i want to append the text to each of these lines of my filenewoutputfile.txt should be
Total Amount : 43.35
Record Count:9
Regards,
Vasa Saikumar.
... (2 Replies)
Hello All,
Iam using below method to sort and compare files. First iam doing sorting and changing the same file and then doing comparing and taking the final result to another file.
sort -o temp.txt file1
mv temp.txt file1
sort -o temp.txt file2
mv temp.txt file2
sort -o temp.txt... (6 Replies)
Hello,
I am writing a small one liner script to display the tables in my database.
I am working with Centos 5.5 and postgresql
the command is
"psql -c "\dt" | awk '{print$3}'"
I just want the 3rd column from the result set, but now the problem is I am getting the third column but with... (3 Replies)
Hi,
I have created a cron job on IBM AIX but it is not working in desired manner !
Here are the steps which I have followed :-
#!/bin/ksh
#------------------------------------------------------------------
find /some/file/at/the/user/side/test.log -exec cp {}... (8 Replies)
I want to compare 2 files and create third file with uncommon content.
e.g.
file1
ajay suhas tom nisha vijay mahish
file2
ajay suhas tom nisha
expected output file content
vijay mahish
Is it possible in single command ?
Thanks,
Ajay (6 Replies)
I use many different machines at work, each with different versions of o/s's and installed applications. Sed in vi is particularly inconvenient in the sense that sometimes it will accept the "\r" as a carriage return, sometimes not. Same thing with "\n". For instance, if I have a list of hosts... (7 Replies)
hello everyone,
i really need your help to write a script which would just print following kind of result into a text file (result.txt)
XYZ test Results
ID: <unique-id> Date: <date>
-------------------------------------------------
| Task | Result | Time |... (3 Replies)
Hi All,
I need some help to effectively parse out a subset of results from a big results file.
Below is an example of the text file. Each block that I need to parse starts with "reading sequence file 10.codon" (next block starts with another number) and ends with **p-Value(s)**. I have given... (1 Reply)
I have written a shell script which looks like below:
grep -v ',0,' ./DATA/abc.001 > ./DATA/abc.mid
egrep $GREPSEARCH ./DATA/ebc.mid > ./DATA/abc.cut
the variable GREPSEARCH has values like the below:
... (3 Replies)