How to include file pattern in find command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to include file pattern in find command?
# 1  
Old 11-15-2013
How to include file pattern in find command?

Hi
I've to remove the files which has the following file pattern in path /home/etc/logs
Code:
fnm_HST_date1
fnm_hst_date1
fnm_HST_date2

I've used the following code to to remove the files having file names like "HST" .
Code:
#!/usr/bin/ksh
set -x
file_path=/home/etc/logs
file_nm=HST
find $file_path -name "*$file_nm*" -type f -mtime +30 -exec rm -f {} \;

But how can I modify the above find command to include the pattern like "hst"

Please suggest .
# 2  
Old 11-15-2013
If you have gnu find use
Code:
 -iname

for case insensitive match.

otherwise, try like this for example :
Code:
find . -name '[fF]2'

to match
Code:
f2 
F2

This User Gave Thanks to greet_sed For This Post:
# 3  
Old 11-17-2013
Code:
names="fnm_HST_date1 fnm_hst_date1 fnm_HST_date2"
names=`echo $names | sed 's/ / -o -name /g; s/^/-name /'`
find $file_path \( $names \) -type f -mtime +30 -exec rm -f {} \;


Last edited by MadeInGermany; 11-17-2013 at 12:48 PM.. Reason: ( ) needed
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies

2. Shell Programming and Scripting

Include strings between a pattern

Hi, I have two files: File1: sample statements1 <UID = " " PWD = " "> sample statements2 File2: UID ="admin" PWD ="password" (6 Replies)
Discussion started by: manid
6 Replies

3. Shell Programming and Scripting

Find Command Include Sub Directory

This script writes the output files to FILES but I don't want to exclude all directories from ABC_CHQ and LYS_ADV, I want to include one sub directory name process which is under ABC_CHQ and LYS_ADV in the search. Right now its excluding everything from prune directories such as ABC_CHQ, LYS_ADV... (10 Replies)
Discussion started by: John William
10 Replies

4. Shell Programming and Scripting

Find big file include current date

Hi, I want to put script. The script is to show file that larger than 100MB include current date (eg: today date). After find the date, it will compress list file and split the tar.gz file. Any idea how to do that? This bash script will run auto everyday. It's will transfer will to other... (12 Replies)
Discussion started by: mzainal
12 Replies

5. Shell Programming and Scripting

Mention file include on command line: awk

Hi All: I need your help please. I have a include file *.awk , and I would want to know if it's there a option's awk where I can use this file include, for example: awk -f decodifica_bitmap.awk cadena_hex.txt -e /home/snh/Awk/include/funciones.awk > sal.out it give error: awk:... (1 Reply)
Discussion started by: solaris21
1 Replies

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

7. Shell Programming and Scripting

Find command to delete a pattern

Hi all i have a directory where it has files as shown below.Using find command how can i delete files which were modified more than 20 days ago and having the pattern jnhld15231 or jnhld15232. find ./ -name "jnhld15231^" -type f -mtime +20 -exec rm {} \; find ./ -name "jnhld15232^" -type f... (2 Replies)
Discussion started by: morbid_angel
2 Replies

8. Programming

Cannot find include file: <sqlca.h>

All, I am getting the following error License : Got the license for Sun WorkShop Compiler C SPARC continuing.. "rlnseg_test.c", line 300: cannot find include file: <sqlca.h> "rlnseg_test.c", line 417: undefined symbol: sqlca "rlnseg_test.c", line 447: undefined symbol: sqlca... (2 Replies)
Discussion started by: thana
2 Replies

9. Shell Programming and Scripting

awk command to find particular pattern in file.

Hi I am using the following command to look for anything other than "0000" in a comma seperated file on 11th field. Note: I am looking for "0000" including the double quotes. nawk -F"," '$11!='"0000"'{print $11}' file This is showing incorrect result. Help is appreciated (2 Replies)
Discussion started by: pinnacle
2 Replies
Login or Register to Ask a Question