Article 127220 of comp.os.vms:
Path: nntpd.lkg.dec.com!pa.dec.com!news1.digital.com!nntp-hub2.barrnet.net!newsfeed.internetmci.com!news.sprintlink.net!in2.uu.net!psinntp!psinntp!psinntp!psinntp!eco.twg.com!news
From: mike@tao.eco.twg.com (This space intentionally left blank)
Newsgroups: comp.os.vms
Subject: Re: DCL string search and destroy
Date: 16 Aug 1995 21:11:05 GMT
Organization: The Wollongong Group (East Coast Operations)
Lines: 193
Message-ID: <40tmta$llb@eco.twg.com>
References: <DDEK54.1Fp@nntpa.cb.att.com>
NNTP-Posting-Host: tao.eco.twg.com

In article <DDEK54.1Fp@nntpa.cb.att.com>, reed@cbict3.cb.att.com (Brian Reed) writes:
>
>In article <1995Aug15.161634@servax.fiu.edu>, jescal01@servax.fiu.edu (Jorge 'Ichthus' Escala <><) writes:
>>
>>I am trying to come up with a DCL script that will search a text file
>>for lines containing a particular string of text and if found, delete
>>those lines. Has anyone come up with a way to do this? If so can you
>
>$search file.name string/match=nand (/output=file.new)

Sure, you can do it that way if you like, but if you want to have a much
more complex solution (and one that lets you substitute text for the
matching portion of the lines...) you can use EDITALL.COM, a little utility
procedure I wrote many years ago when I needed to change a logical name in
about 800 files spread over 300 directories:

   ----------------------------- clip here -----------------------------

$!	EDITALL.COM - Edit all matching strings in all files matching spec. 
$!
$!                  
$!   Syntax:
$!
$!     @EDITALL <file-spec> <search-string> <replacement-string> [<occurances>]
$!                                 
$!	If any required parameter is not given, it will be asked for.
$!            
$!
$!  Semantics:
$!
$!	This procedure will search all files matching the given file
$!	specification (wildcards allowed) for all strings matching the
$!	given search string, and replace them with the given replacement
$!	string.  You may, optionally, specify the number of occurances to
$!	change, with all occurances being the default.  If you specify, for
$!	example, "3" as the number of occurances, then the first three
$!	occurances of the given search string in each matching file will
$!	be replaced.  If there are not enough occurances in a file there
$!	is no error.
$!
$!	EDT is used to effect the replacements, so any file characteristic
$!	changes	that happen do so according to EDT rules.  Be aware of this!
$!
$!
$!	Copyright 1988 Michael D. Bartman
$!	all rights reserved
$!
$!	Permission is hearby granted for all use, commercial or
$!	non-commercial, provided that this copyright notice and the
$!	other contents of this procedure remain unchanged.
$!	No warranties, implied or otherwise, are made as to its usefulness,
$!	functionality, correctness or suitability for any purpose.  The user
$!	assumes all responsibility for any damage that may result from
$!	the use of this procedure and the author disclaims all
$!	responsibility.  If there's a problem I will pretend I've never
$!	heard of this procedure.
$!
$!	In short: use it if you want to and at your own risk.  If you break
$!	it you own all the parts.
$!
$!========================================================================
$! 
$!	Define some handy symbols and defaults
$!                                           
$  sfile	= "SYS$SCRATCH:EDIT_ALL_S.TEMP"
$  efile	= "SYS$SCRATCH:EDIT_ALL_E.TEMP"
$!
$  say		= "WRITE SYS$OUTPUT "
$  put		= "WRITE EDITFILE "
$!                             
$!------------------------------------------------------------------------
$!
$  on control_y then goto ABORT
$!
$!------------------------------------------------------------------------
$!	Get the parameter values one way or the other
$!                      
$  file_spec		= "''p1'"
$  srch_str	= "''p2'"
$  replacement_string	= "''p3'"
$  occurances		= "''p4'"
$!
$GET_FILE_SPEC:
$  if ("''file_spec'" .nes. "") then goto GET_SRCH_STR
$  inquire/nopunctuation file_spec "File search specification: "
$  goto GET_FILE_SPEC
$!
$GET_SRCH_STR:
$  if ("''srch_str'" .nes. "") then goto GET_REPLACEMENT_STRING
$  inquire/nopunctuation srch_str "String to search for: "
$  goto GET_SRCH_STR
$!
$GET_REPLACEMENT_STRING:
$  if ("''replacement_string'" .nes. "") then goto GET_OCCURANCES 
$  inquire/nopunctuation replacement_string "Replacement string: "
$  goto GET_REPLACEMENT_STRING
$!
$GET_OCCURANCES:       
$  if ("''occurances'" .eqs. "") then occurances = 0                      
$!
$!------------------------------------------------------------------------
$!  Have parameters now.  Next we have to get a list of which files that
$!  match the specification actually have the search string in them.
$!                                                                        
$  if (f$search("''sfile'") .nes. "") then -
	set protection=(SY:RWED,OW:RWED)  'sfile';*
$  if (f$search("''sfile'") .nes. "") then -
	delete/nolog/noconfirm  'sfile';*
$  search/output='sfile'  'file_spec'  "''srch_str'"
$!
$!------------------------------------------------------------------------
$!  Next we have to read through the SEARCH output and figure out what needs
$!  editing.  We build a command procedure that runs EDT as we go.
$!
$  open/read/error=ABORT   infile    'sfile'
$  open/write/error=ABORT  editfile  'efile'
$!
$READ_FILE_LOOP:
$  read/end=EXIT_FILE_LOOP infile  line
$  line = f$edit(line, "TRIM,UPCASE,COMPRESS")
$  if ("''line'" .nes. "******************************") then -
	goto READ_FILE_LOOP            
$!
$  read/end=EXIT_FILE_LOOP infile  line
$  filename = f$edit(line, "TRIM,UPCASE,COMPRESS")
$  read/end=EXIT_FILE_LOOP infile  line		!  skip the blank line
$  occur_cnt = 1                                          
$  put "$EDIT/EDT/NOCOMMAND  ''filename'"	!  New file...
$!
$READ_LINE_LOOP:
$  read/end=EXIT_LINE_LOOP infile  line		             
$  if (line .eqs. "") then goto EXIT_LINE_LOOP
$!
$CHECK_FOR_SRCH_STR:          
$  srch_loc = f$locate(srch_str, line)		!still got one?
$  if (srch_loc .ge. f$length(line)) then goto READ_LINE_LOOP	!Done this line
$  line = f$extract(srch_loc + f$length(srch_str), -
	 	    (f$length(line)-srch_loc), line)	!remove it
$!
$  put "TYPE ""''srch_str'"""
$  put "SUBS/''srch_str'/''replacement_string'/"
$  if (occur_cnt .eq. occurances) then goto OCCUR_EXCEEDED
$  occur_cnt = occur_cnt + 1
$  goto CHECK_FOR_SRCH_STR 
$!
$OCCUR_EXCEEDED:
$  read/end=EXIT_LINE_LOOP infile  line		
$  if (line .eqs. "") then goto EXIT_LINE_LOOP	! skip to the blank line...
$  goto OCCUR_EXCEEDED
$!
$EXIT_LINE_LOOP:      
$  put "EXIT"
$  goto READ_FILE_LOOP
$!
$EXIT_FILE_LOOP:
$  close/nolog infile
$  close/nolog editfile
$  @'efile'
$  if (f$search("''efile'") .nes. "") then -
	  set protection=(SY:RWED,OW:RWED)  'efile';*
$  if (f$search("''sfile'") .nes. "") then -
	  set protection=(SY:RWED,OW:RWED)  'sfile';*
$  if (f$search("''efile'") .nes. "") then -
	  delete/nolog/noconfirm  'efile';*
$  if (f$search("''sfile'") .nes. "") then -
	  delete/nolog/noconfirm  'sfile';*
$  say "Processing completed normally."
$  goto EXIT
$!
$ABORT:
$  say "Error during processing.  Aborted."
$  close/nolog infile
$  close/nolog editfile
$  goto EXIT
$!
$EXIT:
$  say "Done. "
$  exit
   ----------------------------- clip here -----------------------------


                        -- Mike "enjoy!" Bartman --

==============================================================================
| I didn't really say all the things that I said.  You probably didn't read  |
| what you thought you read.  Statistics show that this whole thing is more  |
| than likely just a hideous misunderstanding.				     |
==============================================================================

==============================================================================
It all started with a seaside summarising Proust competition when I was six.
------------------------------------------------------------------------------



