02-16-2007
Need a Help with sort a text file with some fields
Ive got a file called listacdrs with this structure:
01/09/2006 12:13 p.m. 1.046.528 CF0155.DAT
01/09/2006 12:13 p.m. 1.046.528 CF0156.DAT
01/09/2006 12:13 p.m. 1.046.528 CF0157.DAT
01/09/2006 12:13 p.m. 1.046.528 CF0158.DAT
01/09/2006 12:14 p.m. 466.032 CF0163.DAT
01/09/2006 12:14 p.m. 596.848 CF0162.DAT
01/09/2006 12:14 p.m. 784.896 CF0161.DAT
01/09/2006 12:14 p.m. 948.416 CF0160.DAT
01/09/2006 12:14 p.m. 1.046.528 CF0159.DAT
02/08/2006 08:09 a.m. 40.880 CF2673.DAT
02/08/2006 08:09 a.m. 40.880 CF2675.DAT
02/08/2006 08:09 a.m. 49.056 CF2671.DAT
02/08/2006 08:09 a.m. 57.232 CF2672.DAT
02/08/2006 08:09 a.m. 57.232 CF2674.DAT
07/08/2006 08:09 a.m. 57.232 CF2676.DAT
02/08/2006 08:09 a.m. 57.232 CF2678.DAT
02/08/2006 08:09 a.m. 65.408 CF2677.DAT
08/08/2006 08:09 a.m. 73.584 CF2670.DAT
02/08/2006 08:09 a.m. 73.584 CF2679.DAT
02/08/2006 08:09 a.m. 89.936 CF2668.DAT
12/08/2006 08:09 a.m. 89.936 CF2669.DAT
02/08/2006 08:09 a.m. 106.288 CF2667.DAT
.....
(it has more rows up to the last day of the month.
The FS (Field Separator is a TAB)
I need to sort this file the first field first by month and second by day thirb by year. The first field is dd/mm/yyyy. ive tried different says without success.
The output must be:
02/08/2006 08:09 a.m. 73.584 CF2670.DAT
02/08/2006 08:09 a.m. 73.584 CF2679.DAT
02/08/2006 08:09 a.m. 89.936 CF2668.DAT
02/08/2006 08:09 a.m. 89.936 CF2669.DAT
02/08/2006 08:09 a.m. 106.288 CF2667.DAT
02/08/2006 08:09 a.m. 73.584 CF2670.DAT
03/08/2006 08:09 a.m. 73.584 CF2679.DAT
03/08/2006 08:09 a.m. 89.936 CF2668.DAT
04/08/2006 08:09 a.m. 89.936 CF2658.DAT
04/08/2006 08:09 a.m. 106.288 CF2677.DAT
..
01/09/2006 13:40 p.m 89.936 CF2668.DAT
i found a way to sort this file but i had to change the structure: the comand line is
awk 'BEGIN {OFS="/"} {print $1,$2,$3,$4,$5}' listacdrs|sort -t/ +1 -3 > lista1:
The output of the comamnd is :
cat lista1
02/08/2006/08:31/a.m./1.046.528/CF2910.DAT
02/08/2006/08:31/a.m./1.046.528/CF2911.DAT
02/08/2006/08:31/a.m./1.046.528/CF2912.DAT
02/08/2006/08:31/a.m./1.046.528/CF2913.DAT
02/08/2006/08:31/a.m./1.046.528/CF2914.DAT
02/08/2006/08:31/a.m./1.046.528/CF2915.DAT
02/08/2006/08:31/a.m./425.152/CF2919.DAT
02/08/2006/08:31/a.m./523.264/CF2918.DAT
02/08/2006/08:31/a.m./662.256/CF2917.DAT
02/08/2006/08:31/a.m./883.008/CF2916.DAT
03/08/2006/07:41/a.m./1.046.528/CF2947.DAT
03/08/2006/07:41/a.m./1.046.528/CF2948.DAT
03/08/2006/07:41/a.m./1.046.528/CF2949.DAT
03/08/2006/07:41/a.m./114.464/CF2926.DAT
03/08/2006/07:41/a.m./114.464/CF2927.DAT
03/08/2006/07:41/a.m./122.640/CF2925.DAT
03/08/2006/07:41/a.m./138.992/CF2924.DAT
03/08/2006/07:41/a.m./147.168/CF2939.DAT
03/08/2006/07:41/a.m./171.696/CF2923.DAT
03/08/2006/07:41/a.m./179.872/CF2940.DAT
it sorts this file in this way.
But is there any easier way to sort this file without changing ths structure?
Thansk for your help.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi All,
I am new to unix scripting, please help me in solving this assignment..
I have a scenario, as follows:
1. i have a text file(read1.txt) with the following data
sairam,123
kamal,122
etc..
2. I have to write a unix... (6 Replies)
Discussion started by: G.K.K
6 Replies
2. UNIX for Dummies Questions & Answers
Hi,
I have a comma delimited file. I want to sort the fields alphabetically and again store them in a comma delimited file.
For example, My file looks like this.
abc,aaa,xyz,xxx,def
pqr,ggg,eee,iii,qqq
zyx,lmo,pqr,abc,fff
and I want my output to look like this, all fields sorted... (3 Replies)
Discussion started by: swethapatil
3 Replies
3. Shell Programming and Scripting
Hi,
I am new to PERL.I want to sort all the lines in a file based on 1,2 and 4th filelds.
Can U suggest me a command/function in perl for this operation.. (5 Replies)
Discussion started by: karthikd214
5 Replies
4. Shell Programming and Scripting
My data is something like as shown below. Out of this i want the details of alarms (ex: 1947147711,1947147081......) and the fields( ex :sw=tacmwafabb9:shelf=1:slot=5-2:pport=2)
Once i have these details separated, i want the count of these excluding the duplicates. What is the best possible way... (7 Replies)
Discussion started by: rdhanek
7 Replies
5. Shell Programming and Scripting
HI all
i have a text file file1 like this
004002004545454000001
041002004545222000002
006003008751525000003
007003008751352000004
006003008751142000005
004001005745745000006
i want to sort the file according to position 1-5 and secondary sort by
the last position of file 16-21... (4 Replies)
Discussion started by: naamas03
4 Replies
6. Shell Programming and Scripting
I am looking for perl code to get following o/p. If a line has more than 7 fields then value in field 7 onwards is BHA_GRP1, BHA_GRP2, BHA_GRP3, BHA_GRP4 etc.
Here is example of what I am trying to achieve.
INPUT File:
VAH NIC_TYPE CONFIG SIZE_GB PILO KOM BHA_GRP1 BHA_GRP2 BHA_GRP3......
2... (1 Reply)
Discussion started by: dynamax
1 Replies
7. Shell Programming and Scripting
Hi
I have a file as below
<field1> <field2> <field3> ... <field_num1> <field_num2>
Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields.
I tried this and it doesn't sort on the difference field .. Appreciate your help.
cat... (9 Replies)
Discussion started by: newstart
9 Replies
8. Shell Programming and Scripting
I have a file of ~500,000 entries in the following:
file.txt
chr1 11868 12227 ENSG00000223972.5 . + HAVANA exon . gene_id "ENSG00000223972.5"; transcript_id "ENST00000456328.2"; gene_type "transcribed_unprocessed_pseudogene"; gene_status "KNOWN"; gene_name "DDX11L1"; transcript_type... (17 Replies)
Discussion started by: cmccabe
17 Replies
9. Shell Programming and Scripting
I have the below contents in a file after making the below curl call
curl ... | grep -E "state|Rno" | paste -sd',\n' | grep "Disconnected" > test
"state" : "Disconnected",, "Rno" : "5554f1d2"
"state" : "Disconnected",, "Rno" : "10587563"
"state" : "Disconnected",, "Rno" :... (2 Replies)
Discussion started by: Vaibhav H
2 Replies
10. Shell Programming and Scripting
I want to rearrange the fields of delimited text file after sorting first line (only):
input file:
a_13;a_2;a_1;a_10
13;2;1;10
the result should be:
a_1;a_2;a_10;a_13
1;2;10;13
any help would be appreciated
andy (20 Replies)
Discussion started by: andy2000
20 Replies
LEARN ABOUT SUNOS
dat_strerror
dat_strerror(3DAT) Direct Access Transport Library Functions dat_strerror(3DAT)
NAME
dat_strerror - convert a DAT return code into human readable strings
SYNOPSIS
cc [ flag... ] file... -ldat [ library... ]
#include <dat/udat.h>
DAT_RETURN
dat_strerror(
IN DAT_RETURN return,
OUT const char **major_message,
OUT const char **minor_message
)
PARAMETERS
return DAT function return value.
message A pointer to a character string for the return.
DESCRIPTION
The dat_strerror() function converts a DAT return code into human readable strings. The major_message is a string-converted DAT_TYPE_STA-
TUS, while minor_message is a string-converted DAT_SUBTYPE_STATUS. If the return of this function is not DAT_SUCCESS, the values of
major_message and minor_message are not defined.
If an undefined DAT_RETURN value was passed as the return parameter, the operation fails with DAT_INVALID_PARAMETER returned. The operation
succeeds when DAT_SUCCESS is passed in as the return parameter.
RETURN VALUES
DAT_SUCCESS The operation was successful.
DAT_INVALID_PARAMETER Invalid parameter. The return value is invalid.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard: uDAPL, 1.1, 1.2 |
+-----------------------------+-----------------------------+
|MT-Level |Safe |
+-----------------------------+-----------------------------+
SEE ALSO
libdat(3LIB), attributes(5)
SunOS 5.10 16 Jul 2004 dat_strerror(3DAT)