Extract file names from file and set variable to 'highest' one

 
Thread Tools Search this Thread
# 8  
Old 12-21-2017
Quote:
Originally Posted by SIMMS7400
Thank you Rudi!

I'm getting an error saying:

Code:
Unexpected EOF will looking for matching ')'

What does this message tell you?

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:
Code:
Unexpected EOF will looking for matching ')'

???

Last edited by Don Cragun; 12-21-2017 at 01:28 AM.. Reason: Add another request.
# 9  
Old 12-23-2017
Wow - I feel silly!

I was trying to operate on my phone, but clearly that was a mistake. I've added the closing paren and everything is working as expected.

As always, thank you both!
# 10  
Old 12-27-2017
Would a simple ls not be neater?

Code:
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.


Kind regards,
Robin

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Find a file and set path in variable? SIMMS7400 Shell Programming and Scripting 4 11-09-2016 03:36 AM
Find matching file in bash with variable file names but consisent prefixs cmccabe Shell Programming and Scripting 5 10-19-2016 10:06 AM
FORTRAN: Loop over variable file names saleheen Programming 6 04-25-2015 03:09 PM
Exclude certain file names while selectingData files coming in different names in a file name called dsravanam Shell Programming and Scripting 1 11-16-2014 10:56 AM
Extract file names from a file jricks Shell Programming and Scripting 8 08-14-2012 05:42 AM
how to assign file names to array variable? siteregsam Shell Programming and Scripting 4 02-29-2012 02:08 AM
set a variable to be a list of file names lionheartyoung Shell Programming and Scripting 4 05-02-2011 06:19 PM
command to extract sub-string out of file names lv99 UNIX for Dummies Questions & Answers 5 04-30-2011 12:40 PM
set a variable with latest file name murtymvvs Shell Programming and Scripting 1 12-02-2010 08:40 PM
Set Environment variable from another file rsivasan Shell Programming and Scripting 6 09-03-2010 01:31 AM
Replace variable names in text file with its value vigithvg Shell Programming and Scripting 1 12-24-2009 09:54 AM
Searching for file names in a directory while ignoring certain file names 2reperry Shell Programming and Scripting 2 12-13-2009 10:16 PM
File Names in a Variable in a loop spkandy Shell Programming and Scripting 3 06-11-2009 06:55 AM
Variable assignment for file names. jagannatha UNIX for Dummies Questions & Answers 2 05-29-2003 05:38 PM