I have a script that will be placing a trigger file for other applications.
The user-inputted path is similar to:
"/data/region/NorthAm/Project HAV 8H"
The project path will not change throughout the script. However, pwd changes as the scanning continues in the script. I need to truncate everything after the project directory "/data/region/NorthAm/Project HAV 8H" so I can apply specific subdirectories for additional trigger files. There are hundreds of subdirectories under each main project path that is inputted by the user, so I need this to be an efficient script, but I can't seem to figure out how to get this done.
#!/bin/bash
# client inputted directory 'xdir'
xdir=$1
echo $1
# other application directories
InclDir="Test, Dev, Prod"
# Main Statement
for i in $InclDir
do
echo $i
ndir=$(awk -F/ '{print "/"$2"/",$3"/",$4,"/"$5,"/"%6}`<<< "${xdir}")
echo ${ndir}/${i}
# touch ${ndir}/${i}/${tmp}${dte}.tmp
done
The awk command places spaces in the path, so I know that what I now have doesn't work.
Here is the output of a test run (the touch command commented out for now for obvious reasons)
Test,
/data/ region/ NorthAm /Project HAV 8H 0/Test,
Dev,
/data/ region/ NorthAm /Project HAV 8H 0/Dev,
Prod
/data/ region/ NorthAm /Project HAV 8H 0/Prod
Is "awk" the only way to get this done? Is there a more efficient way to script this?
Your help in this is greatly appreciated!