I have looped every line using the for Loop, now I want to take each line and cut the .tpt.ctl part of it and store it in a variable and use the variable in same loop.
The part I am stuck at is how do I cut the last 8 characters of each line or a single line using cut command
TPT_PATH='/home/ctl/tpt'
CP_PATH='/home/ctl/copy'
for line in filelist.txt ;
do
if [ -f $TPT_PATH/$line ]
then
echo "###################################################################################################" >> $CP_PATH/$line
The problem is when i write the echo statement into the file the file is named as .tpt.ctl, instead i need it to be .copy.vsql
So I want to put a variable inside this loop which takes maiden name of file without .tpt.ctl and then I can use the variable in echo statement >> $CP_PATH/$variable.copy.vsql
---------- Post updated at 01:36 PM ---------- Previous update was at 01:27 PM ----------
the code will take out the all the extensions instead of last 8 characters. i think this is your requirement. i suggest this because extensions can be more than 3 characters also.
---------- Post updated at 02:20 PM ---------- Previous update was at 01:53 PM ----------
hi, you can use the below code also.. i think file extensions can be more tha 3 characters also.
TPT_PATH='/home/ctl/tpt'
CP_PATH='/home/ctl/copy'
for line in filelist.txt ;
do
if [ -f $TPT_PATH/$line ]
then
line=$(echo ${line%*.*.*}).copy.vsql
echo "###################################################################################################" >> $CP_PATH/$line
fi
done
Also note that the first asterisk should not be there. It only works because you are using lazy matching (single percent sign) so the first asterisk is matching zero characters .