Hi All,
I have a unix shell script file as below.
. get_dates.sh
DD=$(printf $LASTREPDATE | cut -c1-2)
MM=$(printf $LASTREPDATE | cut -c3-4)
YY=$(printf $LASTREPDATE | cut -c7-8)
YYYY=$(printf $LASTREPDATE | cut -c5-8)
LASTREPDATE="$DD$MM$YYYY"
LASTREPDATE_I="$DD$MM$YYYY"
DD=$(printf $CURRREPDATE | cut -c1-2)
MM=$(printf $CURRREPDATE | cut -c3-4)
YY=$(printf $CURRREPDATE | cut -c7-8)
CURRREPDATE_I="$DD$MM$YYYY"
FILENAME248="BW3_*248S"
. $APPAREA/check_file.sh "$FILENAME248*_$CURRREPDATE_I" 1>>$JOBOUTFILE 2>>$JOBOUTFILE
RETCODE=$?
if [ $RETCODE -ne 0 ]
then
FILENAME="$FILENAME248*_$LASTREPDATE_I*.CSV*"
cp $BACKUPAREA/$FILENAME $INBOUNDAREA 1>>$JOBOUTFILE 2>>$JOBOUTFILE
if [ $? -ne 0 ]
then
FILENAME=$FILENAME248"_RD"$LASTREPDATE.TXT.gz
FILENAME1=$FILENAME248"_RD"$LASTREPDATE.TXT
cp $BACKUPAREA/$FILENAME $INBOUNDAREA/ 1>>$JOBOUTFILE 2>>$JOBOUTFILE
if [ $? -ne 0 ]
then
write_log.sh "BW3_248-RESTORE" "FAILED 1"
exit 0
fi
gunzip $INBOUNDAREA/$FILENAME 1>>$JOBOUTFILE 2>>$JOBOUTFILE
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
Sheel
June 22, 2012, 5:48am
2
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
clx
June 22, 2012, 5:51am
3
karthi_mrkg:
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
Where the variable $JOBOUTFILE comes from?
sheel:
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
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.
Sheel
June 25, 2012, 7:07am
7
That is the actual code. Did you try it ?