I am writing a shell script that reads a properties file & perfroms some operation.
That is it reads from fist line of the prop file.
Now in this script I want to add a switch which if ENABLED will execute the script and will perform the regular operation.
If DISABLED will exit the program noramally.
I want to put this swich in the same prop file. (i.e. Now the first line of the prop file will be either ENABLED or DISABLED)
Currently I’m using:
cat init_token.properties | while read line
Now before this I want to separately read the value of the switch & then if ENABLED, the while read line should start form the second line of the properties file.
In nutshell, I want to segrigate the reading of the Ist line and then the rest.
Format of init_token.properties:
ENABLED
abc.dat IP 120.210.60.1
xyz.dat PORT 8200
pqr.dat IP 420.24012.4
Script:
#!/bin/ksh
dos2unix init_token.properties &
# PATH for DAT files
DAT_FILE_PATH='.'
cat init_token.properties | while read line
do
# PARAMETER EXAMPLE - <FILENAME> <ATTRIBUTE> <VALUE>
# read FILENAME
FILENAME=`echo "$line" | awk -F " " '{print $1}'`
# read ATTRIBUTE
ATTRIBUTE=`echo "$line" | awk -F " " '{print $2}'`
# read VALUE
VALUE=`echo "$line" | awk -F " " '{print $3}'`
# setting fully qualified filepath name & temporary file
FULLPATH=$DAT_FILE_PATH"/"$FILENAME
TEMP_FILE=tempfile
old='$('$FILENAME'_'$ATTRIBUTE')'
# replace $(<FILEANME>_<ATTRIBUTE>) with VALUE if file exists
if [ -e $FULLPATH ]
then
sed 's/'$old'/'$VALUE'/g' $FULLPATH > $TEMP_FILE && mv $TEMP_FILE $FULLPATH
else
echo 'File '$FULLPATH' does not exists while replacing token '$old
fi
done
exit
something like this, perhaps?