Quote:
Originally Posted by
IND123
Actually I tried with perl script which you have given, but its not working out the way as it has to be, its showing - found once I execute the script and press enter key;
Can I get a solution using unix shell scripts?
If you're determined to do this in the shell rather than in Perl (and I don't mean a thin Perl wrapper around a pipe of shell commands, I mean a proper Perl implementation), you might try something conceptually like the following. The key is remembering that you
already have a perfectly good list of regexps:
ls -lrt /tmp/vinay/act/files |grep "$cdate"| awk '{print $9}' > file_list
for f in `cat files.txt`; do grep "$f" file_list; fi
Instead of running each filename in turn past all of the possible regexps, just dump all the filenames into a file, then grep that file for the "valid" regexps. The output of the above will be a list of all of the filenames matching one or more of the regexps in files.txt, then you can then pipe that list through sort -u to clean it up.
Now, all that said, your ls pipe method here is inefficient, and by using ls, you're throwing away the information on where the files you match actually
are. There's a tool for doing this job in a single operation, and that tool is
find. Half the secret of doing anything well on Unix is knowing the right tool to use.
I infer you have a large list of valid regexps in that 'files.txt' file, so you're probably going to want to generate the find command programmatically. That's something you could do either in Perl or in the shell. You're going to want to construct something that looks basically like this:
find /tmp/vinay/act/files -ctime [or possibly -cmin] [time period here] -a \( -name regexp1 -o -name regexp2 -o -name ... -o -name regexp
n \) -print
You'll need to read find.1 and determine whether you need to use -cmin or -ctime. What this will do is, in a single operation, return to you the full pathnames of all files under /tmp/vinay/act/files created during the specified time period and matching one of more of your target regexps.
It's just like anything else really: Know what the available tools are, and use the right tool for the job.