Unix/Linux Go Back    

UNIX for Beginners Questions & Answers 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

UNIX for Beginners Questions & Answers

Thread Tools Search this Thread Display Modes
Old Unix and Linux 12-20-2017   -   Original Discussion by SIMMS7400
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Join Date: Jul 2012
Last Activity: 20 April 2018, 6:02 PM EDT
Location: San Jose, CA, USA
Posts: 11,207
Thanks: 633
Thanked 3,903 Times in 3,341 Posts
Originally Posted by SIMMS7400 View Post
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.
Sponsored Links
Old Unix and Linux 12-23-2017   -   Original Discussion by SIMMS7400
SIMMS7400's Unix or Linux Image
SIMMS7400 SIMMS7400 is offline
Registered User
Join Date: Apr 2016
Last Activity: 28 January 2018, 12:11 PM EST
Posts: 156
Thanks: 35
Thanked 3 Times in 3 Posts
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!
Sponsored Links
Old Unix and Linux 12-27-2017   -   Original Discussion by SIMMS7400
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
Join Date: Jun 2007
Last Activity: 20 April 2018, 12:32 PM EDT
Location: Lancashire, UK
Posts: 3,510
Thanks: 1,544
Thanked 689 Times in 619 Posts
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,
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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
Extract file names from a file jricks Shell Programming and Scripting 8 08-14-2012 04:42 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
File Names in a Variable in a loop spkandy Shell Programming and Scripting 3 06-11-2009 05:55 AM

All times are GMT -4. The time now is 06:11 PM.