Home Man
Today's Posts

If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

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

Login to Reply

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

I'm getting an error saying:

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


Last edited by Don Cragun; 12-21-2017 at 12: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?

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,
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find matching file in bash with variable file names but consisent prefixs cmccabe Shell Programming and Scripting 5 10-19-2016 09:06 AM
FORTRAN: Loop over variable file names saleheen Programming 6 04-25-2015 02: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 09:56 AM
Extract file names from a file jricks Shell Programming and Scripting 8 08-14-2012 04:42 AM
how to assign file names to array variable? siteregsam Shell Programming and Scripting 4 02-29-2012 01:08 AM
set a variable to be a list of file names lionheartyoung Shell Programming and Scripting 4 05-02-2011 05:19 PM
command to extract sub-string out of file names lv99 UNIX for Dummies Questions & Answers 5 04-30-2011 11:40 AM
Replace variable names in text file with its value vigithvg Shell Programming and Scripting 1 12-24-2009 08:54 AM
File Names in a Variable in a loop spkandy Shell Programming and Scripting 3 06-11-2009 05:55 AM
Variable assignment for file names. jagannatha UNIX for Dummies Questions & Answers 2 05-29-2003 04:38 PM

All times are GMT -4. The time now is 03:19 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password