![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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 |
|
||||
|
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: 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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|