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
Sorting your data with msort iBot UNIX and Linux RSS News 0 05-19-2008 11:20 AM
Sorting data and place them in different folders Vinaykumar1 UNIX for Dummies Questions & Answers 29 05-14-2008 08:47 AM
sorting data using array in ksh ali560045 Shell Programming and Scripting 4 12-04-2007 04:26 AM
Newbie Awk data sorting i_am_a_robot Shell Programming and Scripting 5 05-04-2007 07:33 AM
Delete blocks with no data.. mgirinath Shell Programming and Scripting 1 01-28-2006 06:33 PM

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

Join Date: Jun 2006
Posts: 44
Exclamation Sorting blocks of data

Hello all,

Below is what I am trying to accomplish:

I have a file that looks like this

Code:
/* ----------------- xxxx.y_abcd_00000050 ----------------- */ 

jdghjghkla
sadgsdags
asdgsdgasd
asdgsagasdg

/* ----------------- xxxx.y_abcd_00000055 ----------------- */ 

sdgsdg
sdgxcvzxcbv
rtertwre
tqwetqe
xzcbvzxcb

/* ----------------- xxxx.y_abcd_00000005 ----------------- */ 

sdgsdg
sdgxcvzxcbv
rtertwre
tqwetqe
xzcbvzxcb
I need to sort it so that it looks like this

Code:
/* ----------------- xxxx.y_abcd_00000005 ----------------- */ 

sdgsdg
sdgxcvzxcbv
rtertwre
tqwetqe
xzcbvzxcb

/* ----------------- xxxx.y_abcd_00000050 ----------------- */ 

jdghjghkla
sadgsdags
asdgsdgasd
asdgsagasdg

/* ----------------- xxxx.y_abcd_00000055 ----------------- */ 

sdgsdg
sdgxcvzxcbv
rtertwre
tqwetqe
xzcbvzxcb
So i really want to sort only based on the items within /*----*/

I looked up the forums but could not find anything....any suggestions?
  #2 (permalink)  
Old 07-03-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Alfredo,
Even though your output file does not match with your requirement,
here is how you can keep the dashes and sorting what is inside of it:
Code:
mSorted='Sorted.txt'
rm -f $mSorted
csplit -k b "/-------/" {99}
for mFile in xx??
do
  sort $mFile >> $mSorted
done
  #3 (permalink)  
Old 07-03-2007
alfredo123 alfredo123 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 44
Thanks for you response..on trying that this is the error I get
csplit: b: No such file or directory
sort: open failed: xx??: No such file or directory??

Let me rephrase the question and post the actual file that needs to be sorted:

Code:
/* ----------------- SVAMN14GLBSMGR.c_imds_00000060 ----------------- */ 

insert_job: SVAMN14GLBSMGR.c_imds_00000060   job_type: c 
command: script.sh par1 par2
machine: SVAMN14GLBSMGR
permission: gx,wx

/* ----------------- SVAMN14GLBSMGR.c_imds_00000050 ----------------- */ 

insert_job: SVAMN14GLBSMGR.c_imds_00000050   job_type: c 
command: script.sh par1 par2
machine: SVAMN14GLBSMGR
permission: gx,wx


/* ----------------- SVAMN14GLBSMGR.c_imds_00000055 ----------------- */ 

insert_job: SVAMN14GLBSMGR.c_imds_00000055   job_type: c 
command: script.sh par1 par2
machine: SVAMN14GLBSMGR
permission: gx,wx
This needs to be sorted to:

Code:

/* ----------------- SVAMN14GLBSMGR.c_imds_00000050 ----------------- */ 

insert_job: SVAMN14GLBSMGR.c_imds_00000050   job_type: c 
command: script.sh par1 par2
machine: SVAMN14GLBSMGR
permission: gx,wx

/* ----------------- SVAMN14GLBSMGR.c_imds_00000055 ----------------- */ 

insert_job: SVAMN14GLBSMGR.c_imds_00000055   job_type: c 
command: script.sh par1 par2
machine: SVAMN14GLBSMGR
permission: gx,wx

/* ----------------- SVAMN14GLBSMGR.c_imds_00000060 ----------------- */ 

insert_job: SVAMN14GLBSMGR.c_imds_00000060   job_type: c 
command: script.sh par1 par2
machine: SVAMN14GLBSMGR
permission: gx,wx
How would I go abt doing that?
  #4 (permalink)  
Old 07-03-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Alfredo, 'b' is my test file -- sorry about it.
In your case, please, replace:
Code:
csplit -k b "/-------/" {99}
By:
Code:
csplit -k your_file "/-------/" {99}
  #5 (permalink)  
Old 07-03-2007
alfredo123 alfredo123 is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 44
I got it to work...however I think you might have misunderstood my requirement. I need to sort blocks based on the first line. THe data within the block needs to remain the same --should not change. SO below only the items in bold are what I am concerned about...

So if I have 3 lines

/---S005---/asd
dfasd
asdg

/---S003---/erqwe
dvasd
xcvc

/---S001---/ewrwqer
dsaf
xzcvxc

this needs to be sorted to

/---S001---/
dsaf
xzcvxc

/---S003---/
dvasd
xcvc

/---S005---/
dfasd
asdg

Last edited by alfredo123; 07-03-2007 at 05:15 PM..
  #6 (permalink)  
Old 07-04-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
alternate soln

Code:
paste -d "\t\t\t\t\t\t\n" -s test_sort_file|sort -t_ -n -k3,3 | tr "\t\t" "\n"

Last edited by ranj@chn; 07-04-2007 at 07:59 AM.. Reason: typo
  #7 (permalink)  
Old 07-04-2007
aigles's Avatar
aigles aigles is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,417
You can try something like that :
Code:
awk '
   /^\/\* ---.*--- \*\// && NF==5 { hdr=$3}
   { printf("%s.%09d\t%s\n", hdr ,NR, $0) }
' sort_blk.txt | sort -k1,1 | cut -f2-
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 08:34 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