Hi,
Again I must apologise for my inadequacies as a scripter, I need a simple script to select the last section of a variable. I know how to use awk print basically, but can't find how to select the last portion. Please see my cut-down script below;
#!/usr/bin/ksh
file="/home/thomasm/test.txt"
first=`echo $file | awk -F"/" '{print $1}'`
last=`echo $file | awk -F"/" '{print $3}'`
echo $first $last
exit
This script picks up the first and last segments (in this case) but I expect variables of between 0 and 10 sections, I could code a cumbersome set of loops, but I'm sure there must be an easier way.
Cheers,
Mark T.
Again I must apologise for my inadequacies as a scripter, I need a simple script to select the last section of a variable. I know how to use awk print basically, but can't find how to select the last portion. Please see my cut-down script below;
#!/usr/bin/ksh
file="/home/thomasm/test.txt"
first=`echo $file | awk -F"/" '{print $1}'`
last=`echo $file | awk -F"/" '{print $3}'`
echo $first $last
exit
This script picks up the first and last segments (in this case) but I expect variables of between 0 and 10 sections, I could code a cumbersome set of loops, but I'm sure there must be an easier way.
Cheers,
Mark T.