Sample Header Ad - 728x90

How to do find and replace strings on file after it is being modified

0 votes
2 answers
501 views
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?
Asked by Lauris Kārkliņš (1 rep)
May 30, 2020, 05:18 PM
Last activity: Jul 17, 2020, 02:07 PM