Hi all,i am very new to shell and awk scripting,..hope u guys can help...
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 but i cannot think how to exclude the first line to not add '1' before the line:
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