Currently I am building one script to grep region records in the config file based on parameter and then I am creating a text file with that output and I am reading the source file path in that output file. Now I need to pass one more parameter like module based upon that it has to create a text file.
My script:
#!/bin/bash
SOURCE_CONF="./test.properties"
#input region name
region="$1"
echo $region
cwd=$(pwd)
calu=$(grep $region test.properties > ab.txt)
IFS=$'\n'
#loop to read the config one line at a time
while read p; do
echo $p
a=($(echo "$p" | tr '|' '\n'))
echo "Region is:" "${a[0]}"
echo "path is:""${a[3]}"
path="${a[3]}"
#remove white space before path
echo $cwd
NO_LEAD_SPACE="$(echo -e $path | tr -d '[:space:]')"
echo "path is:"$NO_LEAD_SPACE
# change to path spacified in the config file
sh -c 'cd $NO_LEAD_SPACE && echo "in the subshell" && echo $pwd && echo "exit subshell" && exec pwd'
echo $cwd
echo "--------------------"
done < ab.txt
echo "abc"
My config file:
region | Module |country code | filepath |filename
APJ | WDMD | MYS |/c/Users/vattikun/desktop | MYS*ADPGV*.XML
APJ | WDED | EUR|/c/Users/vattikun/desktop/Payroll Support | EUR*ADPGV*.XML
APJ | WDMD | RER|/c/Users/vattikun/desktop/Payroll Support | RER*ADPGV*.XML
APJ | WDJD | EYZ|/c/Users/vattikun/desktop/Payroll Support | EYZ*ADPGV*.XML
EMA | WDMD | AUS|/c/Users/vattikun/desktop | AUS*ADPGV*.XML
EMA | WDMD | AYS| /c/Users/vattikun/desktop | AYS*ADPGV*.XML
AMS | WDMD |ITI| /c/Users/vattikun/desktop | ITI*ADPGV*.XML
AMS |WDMD |AYS| /c/Users/vattikun/desktop | AYS*ADPGV*.XML
ETIME | WDMD |ADP /c/Users/vattikun/desktop | ADP_WDET_JOBCODE*.XML
ETIME | WDMD |AEP| /c/Users/vattikun/desktop | AEP_WDET_JOBCODE*.XML
grep $region test.propertieswill match lines you don't want. For example, ifregion=XML, all of the entries will match. A better version isgrep "^ *${region}\\>" test.properties. Andsh -c 'cd $NO_LEAD_SPACE && ...'won't work because the single quotes don't interpolate the variable into the command, and NO_LEAD_SPACE isn't exported. It would work better to use(cd $NO_LEAD_SPACE && ...)instead.