Using awk, since that is what I am using to create a file from another, how may I prefix a line with text if the line contains certain text?
The input file is a list of file names, the output file is effectively a unix script to copy files.
However, I wish to condition any line which contains
/initXYZ.ora
or
/spfileXYZ.ora
or
/lkXYZ
(where XYZ is a variable: srcdb)
to prefix with # in the result.
The calling script has the line:
# Create backup and recovery scripts
awk -f bandr.unix backuploc=$despath rscript=$restorescript olddb=$srcdb newdb=$desdb $filelist>$backupscript
$despath would be something like /backup
$srcdb might be MYDB
$desdb might be TOBEDECIDED
$restorescript would be smth like restoreMYDB.unix
$filelist is filelist.txt
$backupscript might be backupMYDB.unix
the code for bandr.unix:
the final printf (creates recovery script) line is the one which should prefix the line with # if the condition is met.
Thanks in advance
Applications Support
UK
The input file is a list of file names, the output file is effectively a unix script to copy files.
However, I wish to condition any line which contains
/initXYZ.ora
or
/spfileXYZ.ora
or
/lkXYZ
(where XYZ is a variable: srcdb)
to prefix with # in the result.
The calling script has the line:
# Create backup and recovery scripts
awk -f bandr.unix backuploc=$despath rscript=$restorescript olddb=$srcdb newdb=$desdb $filelist>$backupscript
$despath would be something like /backup
$srcdb might be MYDB
$desdb might be TOBEDECIDED
$restorescript would be smth like restoreMYDB.unix
$filelist is filelist.txt
$backupscript might be backupMYDB.unix
the code for bandr.unix:
Code:
BEGIN {
FS = OFS = "/"
}
# Skip lines with "temp*.dbf".
toupper($0) ~ /TEMP[^\/]*\.DBF$/ { next }
{
backup = backuploc $0
# Make new folder (if not present)
printf "mkdir -p $(dirname %s) 2> /dev/null\n",backup
# Copy file
printf "cp -p %s %s\n", $0, backup
# destination is to be decided
gsub(olddb,newdb)
printf "cp -p %s %s\n", backup, $0 >rscript
}
the final printf (creates recovery script) line is the one which should prefix the line with # if the condition is met.
Thanks in advance
Applications Support
UK