0

Trying to achieve following:

1) New file gets uploaded with the same file name but with new content

2) Event triggers that checks the file for specific strings and replaces them

3) The file can be saved in place(might be a loop) or new copy of the file is created with the modifications.

For the event catching tried to use direvent and incron, both can catch the event however there are problems with launching the commands to find and replace the strings in that file.

For the find and replace functionality tried to use sed and perl.

SED+INCRON: /path to file folder/ IN_MODIFY /bin/sed -i 's+/pub/+/+g' filename.xml

DIREVENT+PERL:

direvent.conf content
watcher {
    path /path to file/;
    event write;
    command "/usr/bin/perl script.pl";
}

script.pl content
#!/usr/bin/perl
use strict;
use warnings;

perl -pe 's/old_string/new_string' filename.xml

Could someone suggest an idea?

1
  • Are you trying to call perl from a perl script?
    – Shawn
    Commented Jun 3, 2020 at 11:00

2 Answers 2

0

I don't really understand your question, but I think what you want is:

perl -i -pe 's/oldstring/newstring/g' /some/file

If you run this command in a shell (or a shellscript) it will replace oldstring by newstring everywhere in /some/file

0

Note that in your code, you search for "path to file folder" but then forget of that path in the sed/perl command (not sure the relative path in that case, but in my tests it defaults to /).

Why not just use incron monitor the file itself and use

/path/to/file.xml IN_MODIFY,IN_NO_LOOP /bin/sed -i 's+/pub/+/+g' $@

NOTE: IN_NO_LOOP is to prevent the sed command to trigger the same event on the modification.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .