I am new with bash + awk scripting, i try and error below scripts to get the desired output but ended with error. My scenario and desired output is as per below ;
- I have 2 types of reports for different apps i.e. for 2 apps the files are = BHA_APP1_userLogin.csv & BHA_APP1_userRole.csv, BHA_APP2_userLogin.csv & BHA_APP2_userRole.csv
- I use awk scripting to combine the 2 reports into 1 report and the final output files will be = report_APP1.csv and report_APP2.csv (i have tested the awk script and it's working; both reports are generated as per expectation), in other words; BHA_APP1_userLogin.csv + BHA_APP1_userRole.csv = report_APP1.csv, BHA_APP2_userLogin.csv + BHA_APP2_userRole.csv = report_APP2.csv
- Once i have report_APP1.csv & report_APP2.csv, i need to combine these 2 reports into 1 final report which is ABC_RPT.csv using cat command; cat APP1.csv report_APP2.csv > ABC_RPT.csv
Appreciate your kind help. Thx.
FYR;
Below script (ABCID.sh) is written but executed with below error;
./ABCID.sh: line 28: -v: command not found
cat: report_APP2.csv: No such file or directory
./ABCID.sh: line 28: -v: command not found
cat: report_APP1.csv: No such file or directory
Line 28 is below;
outputfile=$(echo ${node[$arr]} | awk -F, '{print $3}')
Manual script i use to get the expected results (report_APP1.csv & report_APP2.csv);
awk -vFPAT='([^,]*)|("[^"]+")' -v instanceName=APP1 -f Merge_rpt.awk BHA_APP1_userLogin.csv BHA_APP1_userRole.csv
cat report_APP1.csv report_APP2.csv > ABC_RPT.csv
script written : ABCID.sh
#!/bin/bash
export PATH=/usr/local/bin:/usr/bin:/bin:/sbin
export SCRIPT=$(readlink -f "$0")
export SCRIPTPATH=$(dirname "$SCRIPT")
export ABC_FOLDER=`echo $SCRIPTPATH | awk -F"ABC" '{print $1}'`ABC
source $ABC_FOLDER/config/ABC.ini
source $ABC_FOLDER/scripts/common/ABCFunctions.sh
export ABC_LOGFILE=$SCRIPTPATH/mbbID.out
cd $SCRIPTPATH
mergescript=$SCRIPTPATH/Merge_rpt.awk
ABC_file=$SCRIPTPATH/ABC_RPT.csv
declare -A node
node[APP1]=APP1,BHA_APP1,report_APP1
node[APP2]=APP2,BHA_APP2,report_APP2
cat /dev/null > $ABC_file
for arr in "${!node[@]}";
do
instance=$(echo ${node[$arr]} | awk -F, '{print $1}')
file=$(echo ${node[$arr]} | awk -F, '{print $2}')
outputfile=$(echo ${node[$arr]} | awk -F, '{print $3}')
awk -vFPAT='([^,]*)|("[^"]+")' -v instanceName=$instance -f $mergescript ${file}_userLogin.csv ${file}_userRole.csv
cat $outputfile.csv >> $ABC_file
done