![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| unix shell basic | akagi07 | Shell Programming and Scripting | 1 | 11-27-2007 11:18 AM |
| need a quick basic shell script help | eb222 | Shell Programming and Scripting | 6 | 11-22-2007 09:00 AM |
| basic shell scripting question | convenientstore | Shell Programming and Scripting | 3 | 05-27-2007 10:21 PM |
| shell program for sorting strings in an alphabetical order | bp_vanarse | Shell Programming and Scripting | 1 | 10-25-2006 10:41 AM |
| basic c-shell help | ayalex | Shell Programming and Scripting | 0 | 01-31-2006 10:22 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Helpless in basic shell sorting
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 (which i get from this forumn also - thx (forget the name) ) and modified a bit: 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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|