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


Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by SIMMS7400
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 17 January 2018, 1:40 PM EST
Location: San Jose, CA, USA
Posts: 10,913
Thanks: 608
Thanked 3,817 Times in 3,261 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; 3 Weeks Ago at 01:28 AM.. Reason: Add another request.
Sponsored Links
    #9  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by SIMMS7400
SIMMS7400's Unix or Linux Image
SIMMS7400 SIMMS7400 is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 28 December 2017, 8:19 PM EST
Posts: 153
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 Unix and Linux 3 Weeks Ago   -   Original Discussion by SIMMS7400
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 17 January 2018, 12:01 PM EST
Location: Lancashire, UK
Posts: 3,437
Thanks: 1,492
Thanked 671 Times in 604 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
Reply

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



All times are GMT -4. The time now is 04:22 PM.