views:

91

answers:

2

Hello Everyone,

I'm a beginner in Unix Shell Scripting and Perl Scripting.

I would like to have an example program that teaches me how to update a file contents on a directory. The scenario is, there is a directory which has some n number of files. Among those n number of files, m number of files have been modified. I need to update the contents of the modified files in the directory.

Give me a simple shell script to do this.

Thanks and Regards,

Vijay

+2  A: 

I would do it with find like this:

find your_directory -newermt time_of_last_check -exec modify_script.sh {} \;

where:

your_directory is the directory where you have the files.

time_of_last_check is when you last ran this command

modify_script.sh is the program that you will run to modify the files, it should take one argument, and that is the filename to modify.

Alexander Kjäll
Thank you very much.. A bit helpful. Took too long to understand what exactly it is,..
Invincible
+1  A: 

In Perl

  • To Update a File content see perlfaq5, you will find lot of information regarding File manipulation.You will get a lot of examples of file manipulations.
  • Getting File or Dir Statistics see perl built in function stat.
  • For Traverse a directory tree, see File::Find
Nikhil Jain
@Nikhil - +1 for valiant effort
DVK
Thank you very much!
Invincible