Not able to find the perfect code...Geting confused in between

I have to find last delimiter in each line of a file and store the value after the last '/' in a variable in ksh script...Pls Pls help me:(The file is as shown below:

/opt/apps/cobqa/apps/abadv/bind/advc0007.bnd
/opt/apps/cobqa/apps/abbrio/bind/naac6115.bnd
/opt/apps/cobqa/apps/abbrio/bind/trkc4822.bnd
/opt/apps/cobqa/apps/abbrio/bind/trkc4823.bnd
/opt/apps/cobqa/apps/abcmp/bind/cmpc0105.bnd

I know how to find the last '/' but don't know how to repetitively find it and store it in variable.

Use a while read loop and cut the line using parameter expansion: ${line##*/}

1 Like
awk -F/ '{print $NF}' infile
advc0007.bnd
naac6115.bnd
trkc4822.bnd
trkc4823.bnd
cmpc0105.bnd
1 Like
while read line
do
    x=$(echo "$line" | sed 's:.*/::')
    # work with $x
    echo $x
done < file
1 Like

Hey guys thanks a lot...I will try out and let you know how it worked...:slight_smile:

---------- Post updated at 01:09 PM ---------- Previous update was at 12:16 PM ----------

Is it possible for me to add a new line with some text after each line in this record???

Yes, with every iteration you can print your processed line bit and the some extra line..

1 Like