Find & replace --> create a new file

Hi All,

I have a unix shell script file as below.

My task is

a)to replace 248 to 350 and need to create a new file as BW3_350.sh
b)to replace 248 to 380 and need to create a new file as BW3_380.sh
c)to replace 248 to 320 and need to create a new file as BW3_320.sh

there is no change in the file apart from the above mentioned one. I have to create around 250 files. So i need a to script to do this :slight_smile:

You can create a file with the parameters. This will have all the values that need to be used in place of 248. Read this file in another script using while loop and use sed to replace and create corresponding files.

Parameter File

350
380
320

Script To Replace And Create New Files

while read line
do
        echo "Replacing 280 with $line"
        sed "s/248/${line}/g" file1 > file_${line}.sh
done < parafile

Where the variable $JOBOUTFILE comes from?

WHILE READ LINE --> CAN YOU TELL ME HOW SHOULD I OPEN THE FILE AND INCLUDE IN THE WHILE LOOPE ? CAN YOU GIVE ME THE EXACT CODE PLS?

Having 250 different versions of this script is quite bad form. It will be a maintenance nightmare.

Why not pass the file number as a parameter to the script this example takes suffix (default 250) and prefix (default BW3_) parameters.

It would be called like this:

$ proc_file.sh 250 BW3_
$ proc_file.sh 380 BW3_

proc_file.sh

PREFIX=${2:-BW3_}
SUFFIX=${1:-250}
...
FILENAME248="${PREFIX}*${SUFFIX}S"
...
write_log.sh "${PREFIX}${SUFFIX}-RESTORE" "FAILED 1"
...

I have to do some more thing along with this...yes..i have to get the file permission too in a variable...

say for example...

i have a file with 755 permission...i would like to store this permission in a local variable to use it further for other files.

That is the actual code. Did you try it ?