Searching for file names with variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching for file names with variables
# 1  
Old 11-09-2012
Searching for file names with variables

Hello everyone

We have a problem about searching and copying files with variables.

we have variables like $year $jday $date and we want to search the files whose name contain these variables.

we tried *$year*$jday*$date or with ? instead of *


thank you everyone!!!
# 2  
Old 11-09-2012
You should probably give us examples of the filename patterns you're trying to match
# 3  
Old 11-09-2012
one kind of file name and its path is:
Code:
/media/DATA1/receiver/rc/DATA/INVERSION/ARMT/baz_100_135/dist_60_90/09_245_0800.eqr

we set the variables

set year=`cut -c 1-2 data`
set jday=`cut -c 4-6 data`
set hour=`cut -c 8-9 data`

the other file name is
Code:
 /media/DATA1/receiver/rc/DATA/INVERSION/ARMT/2009.245.08.00.00.ARMT.eqr

These two files are the same but file names are different and we want the first kind of file to replace with the second type of the file name.
# 4  
Old 11-09-2012
Code:
find  /media/DATA1/receiver/rc/DATA/INVERSION/ARMT -name \*$year\*$jday\*$hour\*

# 5  
Old 11-09-2012
We tried te way you said but it could not find the files under the directories..

Here is our code and the result..


Code:
[gurbuz@localhost INVERSION]$ cat stack.csh
#!/bin/csh

foreach dir (`ls -d ARMT`)
cd $dir

foreach drr (`ls -d *baz*`)
cd $drr
echo $drr

foreach drc (`ls -d *dist*`)
cd $drc
echo $drc


ls *_*eqr* > data
set year=`cut -c 1-2 data`
set jday=`cut -c 4-6 data`
set hour=`cut -c 8-9 data`

cd ..
end    
cd ..




cp \*$year\*$jday\*$hour\* /$drr/$drc 

end
cd ..
end


[gurbuz@localhost INVERSION]$ csh st
stack.csh    stack.csh-p  
[gurbuz@localhost INVERSION]$ csh stack.csh
baz_100_135
dist_30_60
ls: No match.
dist_60_90
cp: target `/baz_100_135/dist_60_90' is not a directory
baz_20_90
dist_60_90
cp: target `/baz_20_90/dist_60_90' is not a directory
baz_300_360
dist_60_90
cp: cannot stat `*12*145*22*': No such file or directory

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching a file - and assigning responses to variables (or something)

So first: Sorry if the title is confusing... I have a script I'm writing with a file with several names in it (some other info - but it's not really pertinent...) - I want to be allow the user to delete certain records, but I ran into a problem I'm not sure how to go about fixing. If I were... (6 Replies)
Discussion started by: sabster
6 Replies

2. 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

3. Shell Programming and Scripting

How to create files with two or more variables in its names?

Hi all, Iam writing a perl script to create many files with variables in their name. i am able to do it, if iam using only one variable. But with two variables the file names are NOT getting generated in the way i want. plz help me out. 1. open(SHW,">divw_unsigned_50_50_$k.reset") or die... (4 Replies)
Discussion started by: twistedpair
4 Replies

4. Shell Programming and Scripting

Read variables names from array and assign the values

Hi, I have requirement to assign values to variables which are created dynamically. Below is the code which i am using to achieve above requirement. #!/bin/ksh oIFS="$IFS"; IFS=',' STR_FAIL_PARENT_IF_FAILS="WF_F_P_IF_FAILS1,WF_F_P_IF_FAILS2,WF_F_P_IF_FAILS3" set -A... (1 Reply)
Discussion started by: tmalik79
1 Replies

5. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

6. UNIX for Dummies Questions & Answers

Searching File Names

I am interested in writing a really simple alias to search for duplicates in file names in a given directory. As an example, the file names follow a convention like: TGIFRIDAY_55566_RESTAURANT TGIFRIDAY_98744_RESTAURANT TGIFRIDAY_67778_RESTAURANT TGIFRIDAY_55566_RESTAURANT These are all... (8 Replies)
Discussion started by: Tennesseej
8 Replies

7. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

8. Shell Programming and Scripting

AWK: Retrieving names of variables passed with -v

I'm an experienced awk user, but this one has me stumped. I have an awk script which is called from a UNIX command line as you'd expect: myscript.awk -v foo=$1 -v bar=$2 filename My question is this: is there a mechanism for determining the names of the -v variables within a script? ... (3 Replies)
Discussion started by: John Mac
3 Replies

9. Shell Programming and Scripting

Parsing Directory Names for Use as Bash Variables

Hi all: I have a directory where all of the subdirectories are named by the convention "images_#1:#2_Date." My goal is to get an array for each subdirectory that has the structure (#1,#2, int). I am able to use awk to print each subdirectory's values, but cannot figure out how to get them into an... (6 Replies)
Discussion started by: aefskysa
6 Replies

10. AIX

Simultaneous searching for files (names matching certain criteria) in several directo

Hello everyone, My OS is AIX 5.2 I would like some help in getting command syntax that does the following: 1. Searches simultaneously several directories downward; 2. Checks every subdirectory in each directory (and so on...) for file names that contain certain characters such as “~”, start... (0 Replies)
Discussion started by: Hopeful
0 Replies
Login or Register to Ask a Question