Delete Lines in Large File

Find, replace, find in files, replace in files, regular expressions

Delete Lines in Large File

Postby bcampbellz » Thu Dec 21, 2006 1:14 pm

Hi -- I have a large file (~18MB) that I need to delete most of the lines to extract the useful info.

The file looks like this:

Code: Select all
 Name                 Group          Measured         Modelled         Residual         Weight       Weight*Measured    Weight*Modelled  Weight*Residual  Measurement_sd   Natural_weight
 hed1                 head           97.00000         64.26417         32.73583         1.000000         97.00000         64.26417         32.73583         9.439665        0.1059360   
 no_hed2              head           0.000000         64.26417        -64.26417        1.0000000E-19     0.000000        6.4264170E-18   -6.4264170E-18    9.4396655E+19    1.0593596E-20
 no_hed3              head           0.000000         64.26417        -64.26417        1.0000000E-19     0.000000        6.4264170E-18   -6.4264170E-18    9.4396655E+19    1.0593596E-20
 no_hed4              head           0.000000         64.26417        -64.26417        1.0000000E-19     0.000000        6.4264170E-18   -6.4264170E-18    9.4396655E+19    1.0593596E-20
 no_hed5              head           0.000000         64.26417        -64.26417        1.0000000E-19     0.000000        6.4264170E-18   -6.4264170E-18    9.4396655E+19    1.0593596E-20
 no_hed6              head           0.000000         64.26417        -64.26417        1.0000000E-19     0.000000        6.4264170E-18   -6.4264170E-18    9.4396655E+19    1.0593596E-20
 no_hed7              head           0.000000         64.20142        -64.20142        1.0000000E-19     0.000000        6.4201420E-18   -6.4201420E-18    9.4396655E+19    1.0593596E-20
 no_hed8              head           0.000000         64.14249        -64.14249        1.0000000E-19     0.000000        6.4142490E-18   -6.4142490E-18    9.4396655E+19    1.0593596E-20
 no_hed9              head           0.000000         64.12606        -64.12606        1.0000000E-19     0.000000        6.4126060E-18   -6.4126060E-18    9.4396655E+19    1.0593596E-20
 no_hed10             head           0.000000         64.06625        -64.06625        1.0000000E-19     0.000000        6.4066250E-18   -6.4066250E-18    9.4396655E+19    1.0593596E-20
 no_hed11             head           0.000000         64.03172        -64.03172        1.0000000E-19     0.000000        6.4031720E-18   -6.4031720E-18    9.4396655E+19    1.0593596E-20
 no_hed12             head           0.000000         63.84936        -63.84936        1.0000000E-19     0.000000        6.3849360E-18   -6.3849360E-18    9.4396655E+19    1.0593596E-20
 no_hed13             head           0.000000         63.71377        -63.71377        1.0000000E-19     0.000000        6.3713770E-18   -6.3713770E-18    9.4396655E+19    1.0593596E-20
 no_hed14             head           0.000000         63.64392        -63.64392        1.0000000E-19     0.000000        6.3643920E-18   -6.3643920E-18    9.4396655E+19    1.0593596E-20
 no_hed15             head           0.000000         63.60451        -63.60451        1.0000000E-19     0.000000        6.3604510E-18   -6.3604510E-18    9.4396655E+19    1.0593596E-20
 no_hed16             head           0.000000         63.59885        -63.59885        1.0000000E-19     0.000000        6.3598850E-18   -6.3598850E-18    9.4396655E+19    1.0593596E-20
 no_hed17             head           0.000000         63.58002        -63.58002        1.0000000E-19     0.000000        6.3580020E-18   -6.3580020E-18    9.4396655E+19    1.0593596E-20
 no_hed18             head           0.000000         63.55410        -63.55410        1.0000000E-19     0.000000        6.3554100E-18   -6.3554100E-18    9.4396655E+19    1.0593596E-20
 no_hed19             head           0.000000         63.54683        -63.54683        1.0000000E-19     0.000000        6.3546830E-18   -6.3546830E-18    9.4396655E+19    1.0593596E-20
 no_hed20             head           0.000000         63.54607        -63.54607        1.0000000E-19     0.000000        6.3546070E-18   -6.3546070E-18    9.4396655E+19    1.0593596E-20
 no_hed21             head           0.000000         63.54578        -63.54578        1.0000000E-19     0.000000        6.3545780E-18   -6.3545780E-18    9.4396655E+19    1.0593596E-20
 no_hed22             head           0.000000         63.54676        -63.54676        1.0000000E-19     0.000000        6.3546760E-18   -6.3546760E-18    9.4396655E+19    1.0593596E-20
 no_hed23             head           0.000000         63.53595        -63.53595        1.0000000E-19     0.000000        6.3535950E-18   -6.3535950E-18    9.4396655E+19    1.0593596E-20
 no_hed24             head           0.000000         63.53038        -63.53038        1.0000000E-19     0.000000        6.3530380E-18   -6.3530380E-18    9.4396655E+19    1.0593596E-20
 no_hed25             head           0.000000         63.51732        -63.51732        1.0000000E-19     0.000000        6.3517320E-18   -6.3517320E-18    9.4396655E+19    1.0593596E-20
 no_hed26             head           0.000000         63.52480        -63.52480        1.0000000E-19     0.000000        6.3524800E-18   -6.3524800E-18    9.4396655E+19    1.0593596E-20
 no_hed27             head           0.000000         63.50561        -63.50561        1.0000000E-19     0.000000        6.3505610E-18   -6.3505610E-18    9.4396655E+19    1.0593596E-20
 no_hed28             head           0.000000         63.61039        -63.61039        1.0000000E-19     0.000000        6.3610390E-18   -6.3610390E-18    9.4396655E+19    1.0593596E-20
 no_hed29             head           0.000000         63.75952        -63.75952        1.0000000E-19     0.000000        6.3759520E-18   -6.3759520E-18    9.4396655E+19    1.0593596E-20
 no_hed30             head           0.000000         63.78093        -63.78093        1.0000000E-19     0.000000        6.3780930E-18   -6.3780930E-18    9.4396655E+19    1.0593596E-20
 hed31                head           62.00000         60.35040         1.649600         1.000000         62.00000         60.35040         1.649600         9.439665        0.1059360   
 no_hed32             head           0.000000         60.35040        -60.35040        1.0000000E-19     0.000000        6.0350400E-18   -6.0350400E-18    9.4396655E+19    1.0593596E-20
 no_hed33             head           0.000000         60.35040        -60.35040        1.0000000E-19     0.000000        6.0350400E-18   -6.0350400E-18    9.4396655E+19    1.0593596E-20


Except that it doesn't wrap. I need to delete all of the lines that start with nohed but keep all of the lines that start with hed.

Any help on how to program this would be appreciated.
User avatar
bcampbellz
Newbie
 
Posts: 2
Joined: Thu Dec 21, 2006 12:00 am

Re: Delete Lines in Large File

Postby Mofi » Thu Dec 21, 2006 3:29 pm

With an UltraEdit style regular expression:

Find What: %[ ^t]++no_hed*^p
Replace With:

Code: Select all
%       ... start of a line
[ ^t]++ ... followed by 0 or more spaces/tabs
no_hed  ... followed by this word
*       ... followed by any character 0 or more times
^p      ... and last a DOS line termination (carriage return + line-feed)


Same with a Unix/Perl regular expression:

Find What: ^[ \t]*no_hed.*\p

If the file has Unix line terminations (only line-feed) and you have loaded it without conversion to DOS, use ^n respectively \n instead of ^p or \p.

If your file is really LARGE, do not open it. Use this regular expression with the Replace In Files dialog with appropriate file specifications.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Delete Lines in Large File

Postby bcampbellz » Thu Dec 21, 2006 3:43 pm

:D Hi Mofi -- Thanks! Worked like a charm! Enjoyed visiting your beautiful country on several occasions.
User avatar
bcampbellz
Newbie
 
Posts: 2
Joined: Thu Dec 21, 2006 12:00 am


Return to Find/Replace/Regular Expressions