Find script with input pattern file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find script with input pattern file
# 1  
Old 02-06-2006
Bug Find script with input pattern file

Howdy:
I have a file with 140+ file name patterns. Each prefix can have dozens of files with different extension names.
e.g.
1-S51
1113-G6V
1117-G6V
1119-G6V
1127-G6V
12XW-AF5W
14-UA8N

I need to search in 12 directories, (/data/lgc1/basin_mas to /data/lgc12/basin_mas) for all the files.
The output (e.g. 1-S51___oan160001.1c1_fkd) has to be directed to a file, that lists the creator and the directory it is residing in.

I tried to use find /data/lcg*/basin_mas -name "1-S51*" -exec ls -lart {} \; 2>/dev/null >1.x
in a script (140+ lines long) with plans to cat all the *.x files together.
The script would only find some of the files. Most of the *.x files had a size of zero.
Yet, all 140+ files have at least 1 file on the system.

Can anyone suggest improvements to the script?
Or a script that would read in the prefixes, create a command and output the info?

Thanks.
# 2  
Old 02-06-2006
Post an example that while the find command did not work. Be sure to say which files it missed.
# 3  
Old 02-06-2006
Bug Sample of code output

The code was run in the same bash windows, once as a file and 11 times as commands pasted from the script into the command line.

#!/bin/bash -f
find /data/lgc*/basin_mas -name "1-S51*" -exec ls -lart {} \; 2>/dev/null >2.x
find /data/lgc*/basin_mas -name "1113-G6V*" -exec ls -lart {} \; 2>/dev/null >3.x
find /data/lgc*/basin_mas -name "1117-G6V*" -exec ls -lart {} \; 2>/dev/null >4.x
find /data/lgc*/basin_mas -name "1119-G6V*" -exec ls -lart {} \; 2>/dev/null >5.x
find /data/lgc*/basin_mas -name "1127-G6V*" -exec ls -lart {} \; 2>/dev/null >6.x
find /data/lgc*/basin_mas -name "12XW-AF5W*" -exec ls -lart {} \; 2>/dev/null >7.x
find /data/lgc*/basin_mas -name "14-UA8N*" -exec ls -lart {} \; 2>/dev/null >8.x
find /data/lgc*/basin_mas -name "150-F7U*" -exec ls -lart {} \; 2>/dev/null >9.x
find /data/lgc*/basin_mas -name "16X-AF5W*" -exec ls -lart {} \; 2>/dev/null >10.x
find /data/lgc*/basin_mas -name "2-V5*" -exec ls -lart {} \; 2>/dev/null >11.x

output files
-rw-rw-r-- 1 oneale expl 0 Feb 6 13:12 2.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 13:12 3.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 13:12 4.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 13:12 5.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 13:12 7.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 13:12 6.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 13:12 9.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 13:12 8.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 13:12 10.x
-rw-rw-r-- 1 oneale expl 348 Feb 6 13:12 11.x

output of only non-zero file
-rw-rw-r-- 1 33682 expl 1296 Feb 19 2004 /data/lgc*/basin_mas/2-V5__________________________LEDUC_WABAMUN_iso___________________________________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Jan 15 2004 /data/lgc*/basin_mas/2-V5__________________________REG_WABAMUN_merge___________________________________________.hzd_glb

Now running the commands 1 at a time with ".z" as the extension.

output files
-rw-rw-r-- 1 oneale expl 146 Feb 6 13:08 2.z
-rw-rw-r-- 1 oneale expl 250 Feb 6 13:18 3.z
-rw-rw-r-- 1 oneale expl 250 Feb 6 13:18 4.z
-rw-rw-r-- 1 oneale expl 250 Feb 6 13:18 5.z
-rw-rw-r-- 1 oneale expl 424 Feb 6 13:18 6.z
-rw-rw-r-- 1 oneale expl 521 Feb 6 13:22 7.z
-rw-rw-r-- 1 oneale expl 1565 Feb 6 13:14 8.z
-rw-rw-r-- 1 oneale expl 250 Feb 6 13:20 9.z
-rw-rw-r-- 1 oneale expl 521 Feb 6 13:20 10.z
-rw-rw-r-- 1 oneale expl 2416 Feb 6 13:11 11.z

output of 11.z
-rw-rw-r-- 1 33682 expl 1296 Feb 19 2004 /data/lgc10/basin_mas/2-V5__________________________LEDUC_WABAMUN_iso___________________________________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Jan 15 2004 /data/lgc10/basin_mas/2-V5__________________________REG_WABAMUN_merge___________________________________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 20 2003 /data/lgc2/basin_mas/2-V5__________________________NISKU_______________________________________________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 21 2003 /data/lgc2/basin_mas/2-V5__________________________NISKU_WABAMUN_isochron______________________________________.hzd_glb
-rw-rw-r-- 1 jbutlin expl 924876 May 8 2002 /data/lgc3/basin_mas/2-V5__________________________cnc16000102.2v2_glb
-rw-rw-r-- 1 jbutlin expl 8044 Sep 30 2003 /data/lgc3/basin_mas/2-V5__________________________cnc16000101.2v2_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 7 2003 /data/lgc8/basin_mas/2-V5__________________________WABAMUN_new_________________________________________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 14 2003 /data/lgc8/basin_mas/2-V5__________________________LEDUC_______________________________________________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 14 2003 /data/lgc8/basin_mas/2-V5__________________________WABAMUN_reg_________________________________________________.hzd_glb
-rw-rw-r-- 1 33682 expl 8044 Aug 25 2004 /data/lgc8/basin_mas/2-V5__________________________reg16tied01.2v2_glb
-rw-rw-r-- 1 33682 expl 924876 Oct 14 2003 /data/lgc8/basin_mas/2-V5__________________________reg16tied02.2v2_glb
-rw-rw-r-- 1 34124 expl 1296 May 4 2004 /data/lgc8/basin_mas/2-V5__________________________MH_Nordegg__________________________________________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Jul 14 2003 /data/lgc8/basin_mas/2-V5__________________________MH_Wabamun__________________________________________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Aug 28 2003 /data/lgc8/basin_mas/2-V5__________________________REG_WABAMUN_________________________________________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 9 2003 /data/lgc9/basin_mas/2-V5__________________________WABAMUN_____________________________________________________.hzd_glb


Suggestions welcome.
# 4  
Old 02-06-2006
Quote:
Originally Posted by iguanathompson
output of only non-zero file
-rw-rw-r-- 1 33682 expl 1296 Feb 19 2004 /data/lgc*/basin_mas/2-V5__________________________LEDUC_WABAMUN_iso___________________________________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Jan 15 2004 /data/lgc*/basin_mas/2-V5__________________________REG_WABAMUN_merge___________________________________________.hzd_glb
Notice the name of the directory: /data/lgc*/basin_mas/

It seems you have created a directory that quite literally contains an asterisk. That seems to be the only directory you are searching.
# 5  
Old 02-06-2006
Bug Asterik

The asterik is not the problem.

The original script output only found one set of files. (11.x)
And it put lgc* as the directory (not very helpful)

Why does running the commands 1 at a time produce 11 files, with more data in 11.z than 11.x?
The same command one in batch, one typed in.
# 6  
Old 02-06-2006
Quote:
Originally Posted by iguanathompson
The asterik is not the problem.

The original script output only found one set of files. (11.x)
And it put lgc* as the directory (not very helpful)
The asterisk is the problem. Putting lgc* as the directory is extremely helpful. Do you understand what "It seems you have created a directory that quite literally contains an asterisk. " means?
# 7  
Old 02-06-2006
Why two different answers, then.

Okay, I've must have an lgc* directory somewhere.
I can't see it.

The question then is why does the script not return the same results as the single line commands?

#!/bin/bash -f
find /data/lgc*/basin_mas -name "1-S51*" -exec ls -lart {} \; 2>/dev/null >2.x
find /data/lgc*/basin_mas -name "1113-G6V*" -exec ls -lart {} \; 2>/dev/null >3.x
find /data/lgc*/basin_mas -name "1117-G6V*" -exec ls -lart {} \; 2>/dev/null >4.x
find /data/lgc*/basin_mas -name "1119-G6V*" -exec ls -lart {} \; 2>/dev/null >5.x
find /data/lgc*/basin_mas -name "1127-G6V*" -exec ls -lart {} \; 2>/dev/null >6.x
find /data/lgc*/basin_mas -name "12XW-AF5W*" -exec ls -lart {} \; 2>/dev/null >7.x
find /data/lgc*/basin_mas -name "14-UA8N*" -exec ls -lart {} \; 2>/dev/null >8.x
find /data/lgc*/basin_mas -name "150-F7U*" -exec ls -lart {} \; 2>/dev/null >9.x
find /data/lgc*/basin_mas -name "16X-AF5W*" -exec ls -lart {} \; 2>/dev/null >10.x
find /data/lgc*/basin_mas -name "2-V5*" -exec ls -lart {} \; 2>/dev/null >11.x

return this
-rw-rw-r-- 1 oneale expl 0 Feb 6 14:43 2.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 14:43 3.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 14:43 4.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 14:44 5.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 14:44 7.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 14:44 6.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 14:44 9.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 14:44 8.x
-rw-rw-r-- 1 oneale expl 0 Feb 6 14:44 10.x
-rw-rw-r-- 1 oneale expl 348 Feb 6 14:44 11.x

with 11.x containing
-rw-rw-r-- 1 33682 expl 1296 Feb 19 2004 /data/lgc*/basin_mas/2-V5__________________________LEDUC_WABAMUN_iso______________________
_____________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Jan 15 2004 /data/lgc*/basin_mas/2-V5__________________________REG_WABAMUN_merge______________________
_____________________.hzd_glb

But when you run the command separately
find /data/lgc*/basin_mas -name "2-V5*" -exec ls -lart {} \; 2>/dev/null >11.z
you get
-rw-rw-r-- 1 oneale expl 2764 Feb 6 14:45 11.z
with 11.z containing.
-rw-rw-r-- 1 33682 expl 1296 Feb 19 2004 /data/lgc*/basin_mas/2-V5__________________________LEDUC_WABAMUN_iso______________________
_____________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Jan 15 2004 /data/lgc*/basin_mas/2-V5__________________________REG_WABAMUN_merge______________________
_____________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Feb 19 2004 /data/lgc10/basin_mas/2-V5__________________________LEDUC_WABAMUN_iso_____________________
______________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Jan 15 2004 /data/lgc10/basin_mas/2-V5__________________________REG_WABAMUN_merge_____________________
______________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 20 2003 /data/lgc2/basin_mas/2-V5__________________________NISKU__________________________________
_____________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 21 2003 /data/lgc2/basin_mas/2-V5__________________________NISKU_WABAMUN_isochron_________________
_____________________.hzd_glb
-rw-rw-r-- 1 jbutlin expl 924876 May 8 2002 /data/lgc3/basin_mas/2-V5__________________________cnc16000102.2v2_glb
-rw-rw-r-- 1 jbutlin expl 8044 Sep 30 2003 /data/lgc3/basin_mas/2-V5__________________________cnc16000101.2v2_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 7 2003 /data/lgc8/basin_mas/2-V5__________________________WABAMUN_new____________________________
_____________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 14 2003 /data/lgc8/basin_mas/2-V5__________________________LEDUC__________________________________
_____________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 14 2003 /data/lgc8/basin_mas/2-V5__________________________WABAMUN_reg____________________________
_____________________.hzd_glb
-rw-rw-r-- 1 33682 expl 8044 Aug 25 2004 /data/lgc8/basin_mas/2-V5__________________________reg16tied01.2v2_glb
-rw-rw-r-- 1 33682 expl 924876 Oct 14 2003 /data/lgc8/basin_mas/2-V5__________________________reg16tied02.2v2_glb
-rw-rw-r-- 1 34124 expl 1296 May 4 2004 /data/lgc8/basin_mas/2-V5__________________________MH_Nordegg_____________________________
_____________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Jul 14 2003 /data/lgc8/basin_mas/2-V5__________________________MH_Wabamun_____________________________
_____________________.hzd_glb
-rw-rw-r-- 1 34124 expl 1296 Aug 28 2003 /data/lgc8/basin_mas/2-V5__________________________REG_WABAMUN____________________________
_____________________.hzd_glb
-rw-rw-r-- 1 33682 expl 1296 Oct 9 2003 /data/lgc9/basin_mas/2-V5__________________________WABAMUN________________________________
_____________________.hzd_glb
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy data to new file based on input pattern

Hi All, I want to create a new file based on certain conditions and copy only those conditioned data to new file. Input Data is as it looks below. ORDER|Header|Add|32|32|1616 ORDER|Details1......... ORDER|Details2......... ORDER|Details3......... ORDER|Details4............ (10 Replies)
Discussion started by: grvk101
10 Replies

2. UNIX for Beginners Questions & Answers

Reducing input file size after pattern search

I have a very large file with millions of entries identified by @M. I am using the following script to "extract" entries based on specific strings/patterns: #!/bin/bash if ] then file=$1 else echo "Input_file passed as an argument $1 is NOT found." exit; fi MID=(NULL "string-1"... (10 Replies)
Discussion started by: Xterra
10 Replies

3. Shell Programming and Scripting

Search pattern in a file taking input from another file

Hi, Below is my requirement File1: svasjsdhvassdvasdhhgvasddhvasdhasdjhvasdjsahvasdjvdasjdvvsadjhv vdjvsdjasvdasdjbasdjbasdjhasbdasjhdbjheasbdasjdsajhbjasbjasbhddjb svfsdhgvfdshgvfsdhfvsdadhfvsajhvasjdhvsajhdvsadjvhasjhdvjhsadjahs File2: sdh hgv I need a command such that... (8 Replies)
Discussion started by: imrandec85
8 Replies

4. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

5. Shell Programming and Scripting

Script to find duplicate pattern in a file irrespective of case

We have a configuration file in Unix. In that we have entries like below. if it ends with ":", then it is the end of record. We need to find our if there is any duplicate entries like ABCD irrespective of the case. ABCD:\ :conn.retry.stwait=00.00.30:\ :sess.pnode.max=255:\ ... (9 Replies)
Discussion started by: johnjs
9 Replies

6. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

7. UNIX for Dummies Questions & Answers

How i input a pattern into a file where it does not exist

I have a strange problem and i am wondering the best way to tackel it. i have hundres of files. in each of these files i would like to see a representative of each of my animals at the start of each line, in this case mouse, cat, dog, pig, rabbit, in this exact order. However not all of my... (2 Replies)
Discussion started by: cavanac2
2 Replies

8. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

9. Shell Programming and Scripting

Script to find file name for non matching pattern

Hi, I want to list only the file names which do not contain a specific keyword or search string. OS: Solaris Also is there any way ; through the same script I can save the output of search to a CSV (comma seperated) so that the file can be used for inventory purpose. Any assistance will... (5 Replies)
Discussion started by: sujoy101
5 Replies
Login or Register to Ask a Question