Thank you very much 47shailesh. I have tried the code you provided me and I am still not getting correct results. I got this error message while script was executing syntax error on line 1, teletype which I believe have to do with the bc command. Also, I am getting results with newer files that should not be removed.
This script was given to me to fix. I am a mainframe programmer with very little unix experience. The whole idea for this script is we have a text file with file names (like CM.WM449M.P010.M01.PREMMAST.M1007) and retention period in months. For this file, the period is 36 months.
I need to use the text files with the file names and retention period and match each file name with the directory where the actual files reside. If there is a match on the file name, then need to check how old the file is, if it is older than the retention period, for the above example, 36 months (1098 days), I need to move it to different folder so we can free up space. Does that make sense? Any help would be greatly appreciated.
Quote:
Originally Posted by 47shailesh
This is what the above code is doing:
Reading filename and retention from a file.
Doing a month to day conversion with wrong syntax.
Not sure what the use of all_files variable, later checking and storing if the filename is older than retention, which is dependent on incorrect value of period.
Then checking if nonempty filename exist greater than retention then store some info in file else store some other info in additional files. Do you need log of what files were deleted ?
There is no code to delete the obsolete file.
once the script displays right results replace ls {} with rm {}
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)
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)
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)
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)
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)
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)
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)
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)
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
LEARN ABOUT OPENSOLARIS
fnmatch
fnmatch(3C) Standard C Library Functions fnmatch(3C)NAME
fnmatch - match filename or path name
SYNOPSIS
#include <fnmatch.h>
int fnmatch(const char *pattern, const char *string, int flags);
DESCRIPTION
The fnmatch() function matches patterns as described on the fnmatch(5) manual page. It checks the string argument to see if it matches the
pattern argument.
The flags argument modifies the interpretation of pattern and string. It is the bitwise inclusive OR of zero or more of the following flags
defined in the header <fnmatch.h>.
FNM_PATHNAME If set, a slash (/) character in string will be explicitly matched by a slash in pattern; it will not be matched by
either the asterisk (*) or question-mark (?) special characters, nor by a bracket ([]) expression.
If not set, the slash character is treated as an ordinary character.
FNM_NOESCAPE If not set, a backslash character () in pattern followed by any other character will match that second character in
string. In particular, "\" will match a backslash in string.
If set, a backslash character will be treated as an ordinary character.
FNM_PERIOD If set, a leading period in string will match a period in pattern; where the location of "leading" is indicated by the
value of FNM_PATHNAME:
o If FNM_PATHNAME is set, a period is "leading" if it is the first character in string or if it immediately fol-
lows a slash.
o If FNM_PATHNAME is not set, a period is "leading" only if it is the first character of string.
If not set, no special restrictions are placed on matching a period.
RETURN VALUES
If string matches the pattern specified by pattern, then fnmatch() returns 0. If there is no match, fnmatch() returns FNM_NOMATCH, which is
defined in the header <fnmatch.h>. If an error occurs, fnmatch() returns another non-zero value.
USAGE
The fnmatch() function has two major uses. It could be used by an application or utility that needs to read a directory and apply a pattern
against each entry. The find(1) utility is an example of this. It can also be used by the pax(1) utility to process its pattern operands,
or by applications that need to match strings in a similar manner.
The name fnmatch() is intended to imply filename match, rather than pathname match. The default action of this function is to match file-
names, rather than path names, since it gives no special significance to the slash character. With the FNM_PATHNAME flag, fnmatch() does
match path names, but without tilde expansion, parameter expansion, or special treatment for period at the beginning of a filename.
The fnmatch() function can be used safely in multithreaded applications, as long as setlocale(3C) is not being called to change the locale.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|CSI |Enabled |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe with exceptions |
+-----------------------------+-----------------------------+
SEE ALSO find(1), pax(1), glob(3C), setlocale(3C), wordexp(3C), attributes(5), fnmatch(5), standards(5)SunOS 5.11 24 Jul 2002 fnmatch(3C)