0

I am generating simple SVG diagrams by using sed find and replace on some text input. However, I need a more sophisticated find and replace operation involving simple math, to alter certain X and Y values.

E.g. I need to multiply all Y values by a factor of 0.5 or 0.2 or 0.

Because of how I want this to work, it cannot be achieved with a transform operation within the SVG.*

I just need to be able to find, say, all instances of ([0-9.]*)VERT (in sed speak) and replace with the mathematical result of \1 multiplied by the constant I choose.

Zombo
  • 1
  • 62
  • 391
  • 407
user2288772
  • 55
  • 1
  • 3

2 Answers2

0

You could write a simple perl script. Not sure what determines $factor, but this should at least give you a running start.

#! /usr/bin/perl
my $factor=0.5;
while(my $line=<>) {
    if ($line =~ /([0-9.]*)VERT/) {
        my $num = $factor * $1;
        $line =~ s/([0-9.]*)VERT/${num}VERT/;
    }
    print $line;
}

Usage: ./scriptname.pl <file_to_process.txt;

phatfingers
  • 9,770
  • 3
  • 30
  • 44
0
 perl -ape 's/[0-9.]*(?=VERT)/$& * .5/e' file

hope this works +

Sidharth C. Nadhan
  • 2,191
  • 2
  • 17
  • 16