Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Everyone's answers were very helpful to my writing a script that wound up working for me. I actually found a bash script solution yesterday, but wanted to post a Perl answer in case anyone else finds this question through Google.</p> <p>The script that @TLP posted at <a href="http://codepad.org/BFpIwVtz" rel="nofollow">http://codepad.org/BFpIwVtz</a> is an alternative way of doing this.</p> <p>Here is what I ended up writing:</p> <pre><code>#!/usr/bin/perl use Tie::File; my $URL_First = 'http://example.com/foo/bar/'; my $Search = 'path/example.xml'; my $URL_Last = '/path/example.xml'; # This grep returns a list of files containing "path/example.xml" my @files = `grep -ril $Search .`; chomp @files; foreach my $File_To_Edit (@files) { # The output of $File_To_Edit looks like this: "./some_path/index.html" # I only need the "some_path" part, so I'm going to split up the output and only use @output[1] ("some_path") @output = split('/',$File_To_Edit); # "some_path" is the parent directory of "index.html", so I'll call this "$Parent_Dir" my $Parent_Dir = @output[1]; # Make sure that we don't edit the contents of this script by checking that $Parent_Dir doesn't equal our script's file name. if($Parent_Dir ne $0) { # The $File_To_Edit is "./some_path/index.html" tie @lines, 'Tie::File', $File_To_Edit or die "Can't read file: $!\n"; foreach(@lines) { # Finally replace "path/example.xml" with "http://example.com/foo/bar/some_path/path/example.xml" in the $File_To_Edit s{$Search}{$URL_First$Parent_Dir$URL_Last}g; } untie @lines; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload