The UNIX and Linux Forums  


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
Need help in splitting the file Vaddadi Shell Programming and Scripting 3 05-23-2008 10:44 AM
file splitting dhams Shell Programming and Scripting 8 08-23-2007 07:12 PM
[Splitting file] Extracting group of segments from one file to others ozgurgul Shell Programming and Scripting 1 09-14-2006 01:17 PM
File splitting praveen.pinto UNIX for Dummies Questions & Answers 9 02-10-2005 04:32 PM
file splitting praveen.pinto UNIX for Advanced & Expert Users 2 02-10-2005 09:54 AM

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 12-03-2007
dncs dncs is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 10
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.
  #2 (permalink)  
Old 12-03-2007
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,333

Code:
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:


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

Regards
  #3 (permalink)  
Old 12-05-2007
dncs dncs is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 10
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
  #4 (permalink)  
Old 12-05-2007
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,333
Outputs sections where "N" < 8:


Code:
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:


Code:
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
  #5 (permalink)  
Old 12-06-2007
dncs dncs is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 10
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
  #6 (permalink)  
Old 12-06-2007
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,333
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
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 06:32 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