File Splitting

Hi,

I have a big file on Unix Sun Solaris machine where the data is as shown below.

LE8S

line 1
line 2
line 3
LE8E
GE8S

line 1
line 2
line 3
GE8E
LE8S

line 1
line 2
line 3
LE8E

I need to split the above file into two files, one file with all the lines between LE8S and LE8E and another with all the lines between GE8S and GE8E.
There can be any number of LE and GE lines. I need to combine all the lines between into two files.

Please help.

sed -e '/LE8S/,/LE8E/d' -e '/GE8S/d' -e '/GE8E/d' bigfile > GE8_file
sed -e '/GE8S/,/GE8E/d' -e '/LE8S/d' -e '/LE8E/d' bigfile > LE8_file

With GNU sed:

sed '/LE8S/,/LE8E/d;/GE8S\|GE8E/d' bigfile > GE8_file
sed '/GE8S/,/GE8E/d;/LE8S\|LE8E/d' bigfile > LE8_file

Regards

Fraklin Sir,

Thanks for your reply and your code really helps to split the file.
Sir, My requirement is slightly changed now..
Please see if you can help.
Now I have lines in the file as below. Instead of LE and GE, file is now having
NS and NE. Where "N" indicates a number and if it is greater than or equal to 8, I need to pull the lines between into a file and N less than 8 then a seperate file.
Hope I clear about the requirement.
2S

line 1
line 2
line 3
2E
3S
line 1
line 2
line 3
3E
8S

line 1
line 2
line 3
8E
1S
line 1
line 2
1E
10S
line 1
line 2
line 3
10E

Outputs sections where "N" < 8:

awk '
/^[0-9][0-9]*S/ {if(int($1)<8){flag=1;next}}
/^[0-9][0-9]*E/ {if(int($1)<8){flag=0;next}}
{if(flag){print}}
' bigfile

Outputs sections where "N" >= 8:

awk '
/^[0-9][0-9]*S/ {if(int($1)>=8){flag=1;next}}
/^[0-9][0-9]*E/ {if(int($1)>=8){flag=0;next}}
{if(flag){print}}
' bigfile

Regards

Hi,

I tried the code but the first awk command to fetch the "<8" lines is fetching all the rows even between 8S-8E and 10S-10E also.

Regards

I've tested both commands with your file and they work fine for me.
Perhaps a problem with the awk version? Try nawk or gawk.

Regards