Is there a way to update the contents of a file (this file contains a list of sqls) without piping it to a new file using a shell script ? I have 15 processes reading from a file and I want each of them to read the latest updates made to the file so that no process runs the sqls twice ... Is this possible ?
ex or vi with a here or file script works fine, e.g.:
ex myfile < script
ex myfile << EOT
of course, backup myfile before testing.
What do you mean by "update the contents of a file"? Do you want to add to, delete from, or modify the current contents of the file? Depending on exactly what you need to do, my suggestion/recomendation would be to use Perl. For example, using Perl to duplicate Dlonra's suggestion, you'd do it in 1 line like this:
perl -pi.bak -e 's/oldSQLstuff/newSqLStuff/g' myfile
That will do an inline edit of your file as well as create a backup file.
The first solution seems to be working just fine ... Thanx a LOT !
I haven't tried the Perl solution yet .. I shall do that soon ... thanx again ... I really appreciate the inputs ...
The second solution is ok for simple changes (as in my example). If you want to do anything other than simple, ex/vi with scripts is, in my experience, much more flexible. Among other things, you can easily make "multiple passes" over the file.
Also, if you are running your conversion script from a prompt, using vi is fun.
While I do agree that there are times that ex/vi would be a better solution ("use the right tool for the job"), I think I'll take issue with 2 of the first solution statements.
>> If you want to do anything other than simple, ex/vi with scripts is, in my experience, much more flexible.
I'd disagree with that, Perl is not only more flexible, but it's also more powerful than ex/vi with scripts. There are quite a lot of things you can do with Perl that are totaly impossible to do with ex/vi, and as I've shown here, this problem can be solved with Perl in only 1 line as opposed to the 5+ lines used with the ex/vi solution.
>> Among other things, you can easily make "multiple passes" over the file.
That's something that you want to try to avoid, if at all possible. It's far more efficient to process the file in 1 pass. But, if you really want/need to, Perl can easily make multiple passes.
Do you have a UNIX Question?
Unix Home: Unix System Administration
Hints and Tips