Sorting blocks of data

Hello all,

Below is what I am trying to accomplish:

I have a file that looks like this

/* ----------------- 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

/* ----------------- 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?

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:

mSorted='Sorted.txt'
rm -f $mSorted
csplit -k b "/-------/" {99}
for mFile in xx??
do
  sort $mFile >> $mSorted
done

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:

/* ----------------- 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:


/* ----------------- 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?

Alfredo, 'b' is my test file -- sorry about it.
In your case, please, replace:

csplit -k b "/-------/" {99}

By:

csplit -k your_file "/-------/" {99}

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

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

You can try something like that :

awk '
   /^\/\* ---.*--- \*\// && NF==5 { hdr=$3}
   { printf("%s.%09d\t%s\n", hdr ,NR, $0) }
' sort_blk.txt | sort -k1,1 | cut -f2-

Awesome aigles...it works....thanks a bunch!

Alfredo, now that I understand your requirement:

csplit -k input_file "/-------/" {99}
paste -d'|' -s xx?? | sort | tr '|' '\n'