How can I sort it first by name and then by number (like one does in excel for example).
I tried with
and other combinations (k1,2;k2,2...etc) but it sorts either the first field (numeric) or the second one.
Note: I know the input file is exactly like I´m asking it to be, but this is a very small part of the input file where all the data are scrambled. So please take this in account.
If you notice, you can see that it sorts by the first field and the third also, and I don't want that, I just one the first field sorted so that the upper line stays on top and not on below or bottom according to its value.
For this I tried
and
but none of them work.
So I hope you guys can shed some light on this issue as I need to make this easy to read and copy for my weekly reports.
I´m open to any suggestions whether in sort or awk commands.
Hi, for your first question it depends on whether the numbers in the last column are part of the description. If they are this should work:
otherwise you would need something like this:
For the second question that needs the original value intact for the other fields, this is called a stable sort. For GNU sort the option is -s:
Last edited by Scrutinizer; 11-19-2009 at 06:39 PM..
Hi there,
Thanks for the answers provided, and it did helped me with the first question, so thanks Scrutinizer and Steadyonabix.
But for the second part of my questions, the stable sort option is an valid option on my server linux version, I think....
I tried:
and
But it does not sort the 1st field independently of the other....
If you know another way I would be grateful.
Anyway thanks for your help so far.
Hi,
Need to replace last field in a file(/etc/passwd) ,if first filed matches with particular username.
Scenario:
cat testfor1
deekshi:x:7082:7082::/home/deekshi:/bin/bash
harini1:x:7083:7083::/home/harini1:/bin/bash
Here,if first field contains "deekshi", then i should replace... (4 Replies)
OK below is what my sample file looks like. I need to sort by the Primary Key ie: {1:F01SAESVAV0AXXX0466020126} in the first record. Record seperator is $.
I tried sort, but it completely messes it up. I am thinking I will need to use something like awk which understands the record seperator... (6 Replies)
I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below:
column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10
"12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Hi Freinds,
I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output.
Source.txt
1|HYD|NAG|TRA|34.5|1234
2|CHE|ESW|DES|36.5|134
3|BAN|MEH|TRA|33.5|234... (5 Replies)
Hi Friends,
Need Help. I have file1.txt as
File1.txt
|123|A|7267|Hyder|Cross|Sell|7801
|995|A|7051|2008|Lunar|New|Year|Promotion|7801
|996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801
|997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801
File2.txt... (7 Replies)
Hi,
I have two files, one of which I would like to sort based on the order of the data in the second. I would like to do this using a simple unix statement.
My two files as follows:
File 1:
12345 1 2 2 2 0 0
12349 0 0 2 2 1 2
12350 1 2 1 2 2 2
.
.
.
File2:
12350... (3 Replies)
Hi,
I've internally searched through forums for about 2+ hours. Unfortunately, with no luck. Although I've found some cases close to mine below, but didn't help so much.
Actually, I'm in short with time. So I had to post my case. Hoping that you can help.
I have 2 files,
FILE1
... (1 Reply)
Hi,
I have a file that has data in it that says
00:01:48.233 1212
00:01:56.233 345
00:09:01.221 5678
00:12:23.321 93444
The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Hello
I am trying to sort on the last field and it seems to have lost ideas on what to do. the file am sorting looks like this
Tan\da\1223
hey\1234
two\three\think\4579
i want to sort on the last fields (1223, 1234 and 4579).
thank you (2 Replies)