I need to scan the file, searching for this string:
outbox/logs/Client_
Once found, I then need to understand if that string is suffixed with the highest numerical value on the end and then set that name (less the path) to a variable.
There will always be 4 digits and the 'highest' one is always the latest, which I need to extract.
I have done this on batch with ease but struggling here. I am using bash.
Is there an ( somewhere in that code that doesn't have the matching ) that the shell is telling you it can't find?
With over 150 posts in this forum, you been given lots of code that uses command substitutions. Do you really intend to tell us that you can't, with a little bit of trial and error, figure out where the end of that command substitution should be?
Please show us (in CODE tags) what you have tried to solve this problem on your own!
And, please, be very careful when copying diagnostic messages produced by the shell. Trying to search through code to find out what produced an error message when the text you have shown us is not what was actually written by the shell just causes confusion. Did your shell really say:
VAR=$(ls outbox/logs/Client_* | tail -1) # Get the relative-path filename of the last file
VAR="${VAR##*/}" # Trim everything up to the last /
echo $VAR
Maybe I could find a way to get the last entry without a tail (which generates an extra process) then everything apart from the ls to read the directory would be internal to the shell process and probably quick. The sed is a fairly heavy process given that it has so much functionality (that you do not need here)
If this is a once-per-run selection though, this might not matter. It is a choice of coding style which way you choose to go.
Of course, this does not take account of zero matching files and you have to be certain of your current directory given that this is searching a relative path.