Helpless in basic shell sorting [message #282668] |
Thu, 22 November 2007 23:26 |
ashikin_858
Messages: 6 Registered: November 2007
|
Junior Member |
|
|
Hi all;
I need help in sorting and grouping the data in one flat file.The file look like this:
040171011140820070000000009650244002933170003000000075272
1F921338300506 01082007000014000000027665
1H912279980109 01082007000012000000042420
1S503377200110 01082007000014000000005187
1S503377200110 01082007000688000000005188
3SF98
I need to rearrange the file to become like this:
040171011140820070000000009650244002933170003000000075272 3SF98
1
2S503377200110 01082007000688000000005188
1
2F921338300506 01082007000014000000027665
2S503377200110 01082007000014000000005187
2H912279980109 01082007000012000000042420
The Rules:
i)I need to append the whole line that starts with '3' to first line (that start with 0) -lets say length for first line is 70,so new line start from position 71
ii)i also need to replace fisrt character of '1' to become '2'
iii)and group them according to the position 28 till length 3,'688' will have one group and other than '688' (in this case '012','014' )will be grouped in one group (and need to sort in desc order,means 688 first followed by others)
iv)then i need to add 1 for each new group (excluding line that starts with 0)
i have tried this script:
sort -k2 FileLoad.txt.1 |awk '/^1/{sub(/1/,"2")}!x[substr($0,28,3)]++{print 1}1'
The output become like this:
1
3SFVPVKI349009876
1
040171011140820070000000009650244002933170003000000075272
1
2H912279980109 01082007000012000000042420
1
2S503377200110 01082007000014000000005187
2F921338300506 01082007000014000000027665
1
2S503377200110 01082007000688000000005188
Please help....Tq in advance
|
|
|
Re: Helpless in basic shell sorting [message #282671 is a reply to message #282668] |
Thu, 22 November 2007 23:38 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
This is Oracle FAQ forum, not UNIX FAQ. You have placed a question in forum which deals with Oracle-related problems on UNIX operating system.
I'd suggest you to find UNIX-related forum and ask a question there. As your problem has nothing to do with Oracle (or, I don't see any relations with it), topic has been locked. If I was wrong, please, report this message to a moderator and topic will be unlocked.
|
|
|