extract every filename containing certain string in a directory and do some commend per file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract every filename containing certain string in a directory and do some commend per file
# 1  
Old 07-17-2012
extract every filename containing certain string in a directory and do some commend per file

Hi,

Here is my question: suppose I have files like
Code:
1990_8xdaily_atmos.nc
1991_8xdaily_atmos.nc
1992_8xdaily_atmos.nc
1993_8xdaily_atmos.nc
1990_daily_atmos.nc
1991_daily_atmos.nc
1992_daily_atmos.nc
1993_daily_atmos.nc
1990_month_atmos.nc
1991_month_atmos.nc
1992_month_atmos.nc
1993_month_atmos.nc

in my directory.

And what I need to do is to catch the file with 8xdaily in their names and do some commend per file.

Basically, I guess the code should be like
Code:
for file in (what I'm asking)
do (do some commend using $file)
done

Thanks!
# 2  
Old 07-17-2012
Hi.

Basically, it would.

Code:
for file in *8xdaily*; do
  (do some commend using "$file")
done

But it might depend how many files there are.
This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to extract when filename contains file seperator..?

Hi, I want to extract part of filename, for eg: File="010020004_S-TOR-Sort-CASAP_20170519_121504_0007.TXT" here i need first 5 words of file i.e. FilePart="$(echo "${File%"${File#******}"}")" Echo $FilePart 010020004_S-TOR-Sort-CASAP But what if i get filename like below: ... (3 Replies)
Discussion started by: gnnsprapa
3 Replies

2. Shell Programming and Scripting

Extract filename from a given string

I want to extract the filename from a string. This is how I have the rawdata ina file /home/sid/ftp/testing/abc.txt /home/sid/ftp/tested/testing/def.txt /home/sid/sftp/date/misc/hij.txt i want a script which would provide me an output like this Directory ... (10 Replies)
Discussion started by: sidnow
10 Replies

3. Shell Programming and Scripting

Extract data according to keys from filename mentioned in file

Hello experts, I want to join a file with files whosE names are mentioned in one of the columns of the same file. File 1 t1,a,b,file number 1 t1,a,c,file number 1 t2,c,d,file number 2 t2,c,e,file number 2 t2,c,f,file number 2 t2,c,g,file number 2 t3,e,f,file number 3 file number 1... (3 Replies)
Discussion started by: ritakadm
3 Replies

4. Shell Programming and Scripting

Extract string from filename

Hi I need to extract the string from file name filename: FILENAME_STRUT_01032013_XXXXXXX.TXT I want 01032013 from the above file name. number of characters may differ before the required string but underscores(-) are same number i.e. after second underscore. Please advise on this. ... (2 Replies)
Discussion started by: cnrj
2 Replies

5. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

6. Shell Programming and Scripting

How to check if a filename in a directory starts with a certain string

Hello, Trying to iterate over set of file in current directory and check if the file name in that folder matches certain string. This is what I have so far. Here I am checking if the file name starts with nexus, if so echo file name to log file. Getting weird syntax errors. Any help is... (7 Replies)
Discussion started by: scorpioraghu
7 Replies

7. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

8. Shell Programming and Scripting

Extract date from filename and create a new file

Hi, i have a filename CRED20102009.txt in a server 20102009 is the date of the file ddmmaaaa format the complete route is /dprod/informatica/Fuentes/CRED20102009.csv i want to extract the date to create a new file named Parameters.txt I need to create Parameters.txt with this... (6 Replies)
Discussion started by: angel1001
6 Replies

9. UNIX for Dummies Questions & Answers

Extract first line of a file and use as filename

I am trying to find a way to create a script which will extract the first line of a file and then rename the file (or create a new file with the same content as the old file) using the first line as the name. The first line being a single word, that is. I am hopeless at programming, if anyone can... (5 Replies)
Discussion started by: s.plumb
5 Replies

10. Shell Programming and Scripting

extract string portion from filename using sed

Hi All, I posted something similar before but I now have a another problem. I have filenames as below TOP_TABIN240_20090323.200903231830 TOP_TABIN235_1_20090323.200903231830 i need to extract the dates as in bold. Using bash v 3.xx Im trying to using the print sed command but... (11 Replies)
Discussion started by: santam
11 Replies
Login or Register to Ask a Question