in reply to Re^2: replace string from Command Line (updated)
in thread replace string from Command Line

I am trying to update my sql which was written for Teradata DB to be compatible to the DVT. DVT does not accept CAST(CAST(hs_date AS DATE FORMAT 'YYYYMMDD') AS CHAR(08)) as hs_date and only accepts FORMAT_DATE(hs_date, 'YYYYMMDD') as hs_date. I have more than 75 scripts which need to be replaced and compatible to DVT. I have identified these scripts and rather than open each script and replace the string, I thought I could do this from the command line

..... $sql = "select CAST(CAST(hs_date AS DATE format 'YYYYMMDD') AS CHAR(08 +)) as hs_date, " . "device, " . "thrshld as CPU_threshold, " . ...

Replies are listed 'Best First'.
Re^4: replace string from Command Line (updated)
by AnomalousMonk (Archbishop) on Oct 13, 2020 at 21:30 UTC

    I have more than 75 scripts which need to be replaced and compatible to DVT. ... I thought I could do this from the command line
    This sounds like more than just a quick-and-dirty, one-off command-line task. Write yourself a script. Put all the filenames to be processed into a file and pass that filename to your script. Open each file, make a verified backup first, make all changes (and there will probably be others you need to do; these can easily be added to your script), then save the altered file. Only process files that are copies of files saved elsewhere!

    I'd like to provide a pseudo-script example, but I don't have time ATM. Maybe later if no one else steps in first. Just remember that the \Q...\E approach fails if there is any variation in spacing in the substrings to be altered or if they are broken over multiple lines. In that case, a broader approach is needed, but can easily be integrated into a general script.


    Give a man a fish:  <%-{-{-{-<