Skip to content

Instantly share code, notes, and snippets.

@Akronix
Created December 4, 2018 10:23
Show Gist options
  • Save Akronix/7137ea9682eba1d243075970871b3e2f to your computer and use it in GitHub Desktop.
Save Akronix/7137ea9682eba1d243075970871b3e2f to your computer and use it in GitHub Desktop.
To fix the issue of having double quotes inside attribute values in XML files. This scriptSubstitute every double quote (") by its
use utf8;
use feature 'say';
#~ $filename=$ARGV[0];
# uncomment to define the input file here instead of using standard input
#~ my $encoding = ":encoding(UTF-8)";
#~ open (FH, " < $encoding", $filename) or die "Error trying to write on $filename: $!\n";
# uncomment to define the output file here instead of using standard output
#~ $aux_fn = "out2";
#~ open (OUT, " > $encoding", $aux_fn) or die "Error trying to write on $aux_fn: $!\n";
foreach $line (<STDIN>) {
my ($prev, $value, $after) = $line =~ '(.*=")(.*)(" .*)';
#~ say $prev;
#~ say $value;
#~ say $after;
if (not $prev) {
print STDOUT "$line";
next;
}
#~ say $value;
$value =~ s/\"/\&quot;/g;
#~ say $value;
print STDOUT "$prev$value$after\n";
#~ print "$line\n";
}
#~ close(FH);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment