How to search directory for specific file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to search directory for specific file?
# 8  
Old 04-18-2012
Sorry, there was a missing 'fi' that I threw in a moment later. Guess you checked the boards too quickly. The execute problem is that you must set new scripts as executable:

Code:
chmod a+x ./search1

# 9  
Old 04-18-2012
Hi neutronscott, I added the fi and the script ran. I am still not getting correct results. On the rulesx.txt file, I have the following files
CM.WM013M.P010.SECADV.G0011V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0006V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0007V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0010V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0012V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0005V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0004V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0013V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0001V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0003V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0014V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0015V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0002V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0008V00 36 I/P to STAT system
CM.WM013M.P010.SECADV.G0009V00 36 I/P to STAT system
I want to check to see if any of them are older than 36 months. If we take the first one for example on /prod/STAT/seqfiles as you see bellow, the modified date is Sep 01 2010 which is not older than 36 months.
CM.WM013M.P010.SECADV.G0011V00 dataadm 5332600 rwxr-x--- Sep 01 2010
When I run the script, I am getting a match on all 15 files although none of them are older than 36 months. I am not sure why it is picking all 15 files as older than 36 monthsSmilie
Quote:
Originally Posted by neutronscott
Sorry, there was a missing 'fi' that I threw in a moment later. Guess you checked the boards too quickly. The execute problem is that you must set new scripts as executable:

Code:
chmod a+x ./search1

# 10  
Old 04-18-2012
You've text after the 36 in the files? And bc didn't print a bunch of errors...?

Code:
$ read file ret_period <<< 'CM.WM013M.P010.SECADV.G0009V00 36 I/P to STAT system'
$ days=`echo "30.5 * ${ret_period}" | bc`
(standard_in) 1: illegal character: I
(standard_in) 1: illegal character: P
(standard_in) 1: illegal character: S
(standard_in) 1: illegal character: T
(standard_in) 1: syntax error
(standard_in) 1: illegal character: T

put a dummy variable at the end of the read

Code:
while read name ret_period _; do

This User Gave Thanks to neutronscott For This Post:
# 11  
Old 04-18-2012
Thank you very much neutronscott, it worked Smilie. I really appreciate your help with this .
Quote:
Originally Posted by neutronscott
You've text after the 36 in the files? And bc didn't print a bunch of errors...?

Code:
$ read file ret_period <<< 'CM.WM013M.P010.SECADV.G0009V00 36 I/P to STAT system'
$ days=`echo "30.5 * ${ret_period}" | bc`
(standard_in) 1: illegal character: I
(standard_in) 1: illegal character: P
(standard_in) 1: illegal character: S
(standard_in) 1: illegal character: T
(standard_in) 1: syntax error
(standard_in) 1: illegal character: T

put a dummy variable at the end of the read

Code:
while read name ret_period _; do

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to search in specific directory using find?

Hi, Is there any way to use find command and search only specific subdirectories in a directory. for example /home/d1 /home/d2 /home/d3 i want to search in the following directories /home /home/d1 /home/d2 i do not want the find command to search the /home/d3 directory. (6 Replies)
Discussion started by: Little
6 Replies

2. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

3. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

4. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

5. Shell Programming and Scripting

Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as (7 Replies)
Discussion started by: manigrover
7 Replies

6. Shell Programming and Scripting

Urgent request to consider:Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as # Drug_Target_X_Gene_Name:(Where X can be any number (1-1000) (1 Reply)
Discussion started by: manigrover
1 Replies

7. UNIX for Advanced & Expert Users

allow user to use sudo cp on a specific directory and only a specific file

Is there a way to allow a user to use sudo cp on a specific directory and only a specific file? (6 Replies)
Discussion started by: cokedude
6 Replies

8. UNIX for Dummies Questions & Answers

How to search all the files in a directory for a specific string

Hi Guys, I want to search the content of all the files (of a particular type like .txt) in a directory for a specific string pattern. Can anyone help me? Thanks (7 Replies)
Discussion started by: mwrg
7 Replies

9. Shell Programming and Scripting

Search for a file in specific directory

I have to search a file in a prticular directory. filename will be passed through command line. The directory may contain subdirectory. i.e. suppose directory in /u03/appl (it can hard coded in script). This directory may contain subdirectory. $ scriptname.sh filename output should be... (2 Replies)
Discussion started by: jadoo_c2
2 Replies

10. UNIX for Dummies Questions & Answers

Linux shortcutkey to search specific file from a list of directory?!

Hi, I'm the new user of linux/unix. Can I ask that anybody know how to use the linux/unix shortcut key to search a specific file from a list of directory? For example, I know the file name that I want to search. But I forget which directory or location is my desired file put.Got any shortcut... (7 Replies)
Discussion started by: patrick87
7 Replies
Login or Register to Ask a Question