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

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Extract file names from file and set variable to 'highest' one
# 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Programming

FORTRAN: Loop over variable file names

Hi guys I'm a beginner in fortran. So excuse me for my naivety, let me briefly describe what I was trying to do. I have let's say 2 files named reac-1 and reac-2. After opening these files I've to do some calculations, close these files and open the same files again in a loop. So my faulty code... (6 Replies)
Discussion started by: saleheen
6 Replies

3. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

4. Shell Programming and Scripting

Extract file names from a file

I'm trying to extract a list of each .cfg file name mentioned in a file. I've made some progress using sed, but I'm still not there. Any help would be appreciated. My input looks like this: 07:00:00.000 spn redo 08:04:36.200 CMD OBJ_INIT 08:04:37.200 CMD OBJ_INIT ... (8 Replies)
Discussion started by: jricks
8 Replies

5. Shell Programming and Scripting

how to assign file names to array variable?

I wish to assign file names with particular extention to array variables. For example if there are 5 files with .dat extention in /home/sam then i have to assign these 5 files to an array. plz help me how to accomplish this. Thanks in advance. (4 Replies)
Discussion started by: siteregsam
4 Replies

6. Shell Programming and Scripting

set a variable to be a list of file names

Hi all, I am trying to get a list of all the .tif images in my folder and set a variable that holds all the file names using C shell. What is the best way to do it? any help would be greatly appreciated. Yang (4 Replies)
Discussion started by: lionheartyoung
4 Replies

7. UNIX for Dummies Questions & Answers

command to extract sub-string out of file names

I have these files in a directory. It may have more class than the sample below: DEPT_CHEM101LEC_D_20110301.DAT DEPT_CHEM101LAB_D_20110301.DAT DEPT_BIO105LEC_D_20110325.DAT DEPT_BIO105LAB_D_20110325.DAT DEPT_CSC308LEC_D_20110327.DAT DEPT_CSC308LAB_D_20110327.DAT Is there way to extract out... (5 Replies)
Discussion started by: lv99
5 Replies

8. Shell Programming and Scripting

Replace variable names in text file with its value

Hi I have a text file (mytext.txt), the content of which is as following: My name is <@MY_NAME@> and my age is <@MY_AGE@> . Now i have another property file (myprops) which is as following: MY_NAME=abcdefgh MY_AGE=000000 I was wondering, how can i replace the tags of mytext.txt, with its... (1 Reply)
Discussion started by: vigithvg
1 Replies

9. Shell Programming and Scripting

File Names in a Variable in a loop

Hi All , I am having confusion in a shell script. Please guide me. I need to get multiple files (number of files vary time to time, file names are separated by '|') using FTP get from the remote server. Actually, i call the FTP function in a loop. At the last step, i need to move all the get... (3 Replies)
Discussion started by: spkandy
3 Replies

10. UNIX for Dummies Questions & Answers

Variable assignment for file names.

I am trying to process error files in selected directories. I can count the files that are there and export the contents to a file for either emailing or printing. The next step is to move the files to a processed directory with the name changed to .fixed as the last extension. for file in... (2 Replies)
Discussion started by: jagannatha
2 Replies
Login or Register to Ask a Question