×
UNIX.COM Login
Username:
Password:  
Show Password






👤


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

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #8  
Old 12-20-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 16 July 2018, 1:02 AM EDT
Location: San Jose, CA, USA
Posts: 11,406
Thanks: 649
Thanked 3,969 Times in 3,393 Posts
Quote:
Originally Posted by SIMMS7400 View Post
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 12:28 AM.. Reason: Add another request.
Sponsored Links
    #9  
Old 12-23-2017
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 16 July 2018, 6:54 AM EDT
Posts: 159
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
    #10  
Old 12-27-2017
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 13 July 2018, 1:03 PM EDT
Location: Lancashire, UK
Posts: 3,582
Thanks: 1,590
Thanked 706 Times in 633 Posts
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
Sponsored Links
👤 Login to reply

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
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 08:38 AM.

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