Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selective deletion of lines from the file.

Status
Not open for further replies.

skuthe

Programmer
Sep 10, 2002
33
0
0
US
Hi,
I need to verify the next line of the matched pattern in the file and if the next line of the pattern does not match 'SQR' word then delete the lines of the matched pattern.

f.eg : Myfile..

/users/ciim/942ftp.com
-------------------------------------

/users/ciim/abm/com/driverall.com
-------------------------------------
sqr $USR_HOME/driverall.sqr $USR_HOME/driverall.txt

/users/ciim/abm/com/drivers.com
-------------------------------------
sqr $USR_HOME/driver10.sqr ciim/iis $USR_HOME/driver10.txt
sqr $USR_HOME/abm/sqr/driver11.sqr $USR_HOME/driver11.txt
sqr $USR_HOME/abm/sqr/driver12.sqr $USR_HOME/driver12.txt

/users/ciim/942ftp.com
-------------------------------------

/users/ciim/943ftp.com
-------------------------------------

/users/ciim/944ftp.com
-------------------------------------

In the above example I want to search for the pattern..
/users/ciim*
------------
If I find it then I need to check that whether the line that is following the ------- line starts with sqr/SQR.
If this line does not start with sqr/SQR then delete the above two lines of the matched pattern ( /users/ciim*
------------ ).

In the above case my output should like ....

/users/ciim/abm/com/driverall.com
-------------------------------------
sqr $USR_HOME/driverall.sqr $USR_HOME/driverall.txt

/users/ciim/abm/com/drivers.com
-------------------------------------
sqr $USR_HOME/driver10.sqr ciim/iis $USR_HOME/driver10.txt
sqr $USR_HOME/abm/sqr/driver11.sqr $USR_HOME/driver11.txt
sqr $USR_HOME/abm/sqr/driver12.sqr $USR_HOME/driver12.txt


Any and all help will be appreciated. Thanking you in advance.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top