extracting multiple variables from a filename.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting multiple variables from a filename.
# 1  
Old 10-29-2010
extracting multiple variables from a filename.

hi all,

I'm trying to automate some tasks and while I've got the script itself working, I'm having difficulties with automatic file detection and associated variable setting...

for example, in a directory I've got several files... something along the lines of:

xis0_NAME_src.file
xis1_NAME_bkg.file
xis0_NAME_bkg.file
xis1_NAME_src.file

The NAME segment will change from use to use, but I'm looking to make the script automatically detect which file is xis0_*_src.file, which is xis0_*_src.file etc and attach it to each. So far I've tried using something along the lines of:

Code:
xis0_src=`find . -name "xis0*src*"`

but I end up with:

find: xis0_asd_src.pi: unknown option

Any pointers as to a more efficent way of setting this up? CHeers in advance!
# 2  
Old 10-29-2010
Probably it's finding more than one hit, so it's trying to store multiple lines in a single variable. Perhaps if we knew more about the objective we could better craft a reply. You may be looking down the lines of a loop such that
Code:
for file in `find . -name "xis0*src*" -print|sort`
do
   whatever logic you want
done

I added the sort as the find will search (probably) in inode order and if there are subdirectories involved, that could get very messy.


I hope that this gets you started, but post more infor on what you want to do with them and someone may pop up more complete code.




Robin
Blackburn/Liverpool
UK
# 3  
Old 10-29-2010
@u5j84
Could you please clarify ...
What input to you have ?
what output do you need ?
or what behaviour do you expect ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extracting filename

I am using bash and have a filename with a path and extension and want to extract just the filename Have used the following code, oflna gives the file name with extension, but now neet to remove the .texi at the end. oflna=${flnm##*/} oflnb=${${flnm##*/}%.*} echo "flnm: $flnm" echo... (1 Reply)
Discussion started by: Danette
1 Replies

2. Shell Programming and Scripting

Extracting a portion of the filename

Hi I would like to extract the first portion of filename from a list of files. The filename pattern is of the form 123456789_TEXT_TEXT_TEXT_.csv. I want to extract just the numerical portion of this filename from the list of files and then output this into another text file. K (6 Replies)
Discussion started by: kamal_p_99
6 Replies

3. Shell Programming and Scripting

extracting substrings from variables

Hello Everyone, I am looking for a way to extract substrings to local variables. Here is the format of the string variable i am using : /var/x/www && /usr/x/share/doc && /etc/x/logs where the substrings i must extract are the "/var/x/www" and such. I was originally thinking of using... (15 Replies)
Discussion started by: jimmy75_13
15 Replies

4. Shell Programming and Scripting

Extracting variables from echo

Hello all. I can not remember the command to extract a variable from the date command. Basically what I need to do is to store the values of date in variable and rearrange them. I can not remember the command or the syntax to do so. so.. date Mon Mar 8 06:57:19 GMT 2010 $1 $2 ... (12 Replies)
Discussion started by: adelsin
12 Replies

5. UNIX for Dummies Questions & Answers

extracting date from a filename

Hi, I am a beginner in Unix so please bear with me... I have a directory which has files in format: RECF-YYYY-MM-DD-input. For example, RECF-2008-02-25-input. I need to extract the YYYYY-MM-DD substring from this filename and convert that into date and compare it with a date. How do I do that?... (7 Replies)
Discussion started by: laiko
7 Replies

6. Shell Programming and Scripting

Extracting the Filename

Hi, I need to extract the file name without filetype. Suppose in DIR1 if i have files like F1.txt and F2.DOC then i need to return F1 and F2 only with out file types (txt and DOC). I tried with the following code newname = ` $i | cut -d "'." -f1` but it is giving the error " 0403-006... (1 Reply)
Discussion started by: Raamc
1 Replies

7. UNIX for Dummies Questions & Answers

Extracting Filename from Fullpath

Hi, Any help on this would be very appreciated. I capture the full path & filename in a variable like (varFile=/home/user/extfile.txt). Now in my shell script I have to use only the filename part i.e. extfile.txt. How do I extract only the filename part from the variable? Thanks in... (3 Replies)
Discussion started by: njoshi
3 Replies

8. Shell Programming and Scripting

Extracting a users environment variables

Hi Guys, I want to extract users environment variables via a sh script, and for some reason it is not working. According to the su man page: Example 3: Executing command with user bin's Environment and Permissions To execute command with the temporary environment and per-... (2 Replies)
Discussion started by: Tornado
2 Replies

9. UNIX for Dummies Questions & Answers

extracting return of ls -l into variables

If I do "ls -l filename" in a script, it should return something like this: -rw-r--r-- 1 user group 5945 Feb 28 14:24 filename How do I put each of the above strings into a different variable? eg Permissions, username, groupname, date (7 Replies)
Discussion started by: Sniper Pixie
7 Replies

10. UNIX for Dummies Questions & Answers

extracting only the filename without its extenstion

Hi, I have a requirement that i need to store only the filename without its extension. Can anyone please help me to do this. For Example, i have stored the filename in a varialble called fname. I need to extract all the charecters before the first occurence of the dot. If fname has value... (3 Replies)
Discussion started by: lotus123
3 Replies
Login or Register to Ask a Question