The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-23-2007
ashikin_8119 ashikin_8119 is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 10
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0