I have a list of points coordinates in 2 column format first column x-axis, second column y-axis, and I'd like to make a script to rescale the axis.
input file example
4 3
3 6output file example (rescale to 10 10)
10 5
7.5 10
To do that, I first get the biggest coordinate on both column (using sort, head and cut), and then I interpolate all lines using a perl substitute regexp.
So I scripted that :
#!/bin/sh
# run: $ ./normalize x y input_file output_file
X=$1
Y=$2
INPUT=$3
OUTPUT=$4
BIGGEST_FIRST_COLUMN=$(sort -nrk1 $INPUT | head -n1 | cut -d ' ' -f 1)
BIGGEST_SECOND_COLUMN=$(sort -nrk2 $INPUT | head -n1 | cut -d ' ' -f 2)
PERL_CMD="'s!([\d.]+)\s([\d.]+)!(\$1/$BIGGEST_FIRST_COLUMN*$X).\" \".(\$2/$BIGGEST_SECOND_COLUMN*$Y)!e'"
CMD="perl -pe $PERL_CMD $INPUT > $OUTPUT"
echo "Run the following cmd : "
echo $CMD
$CMD
This code output the perl onliner I want to run and then try to run it. At this point, the perl oneliner is working : I can copy-paste it and running it by hand and it gives the correct output. Nevertheless, I got a bug when the script run it automatically :
Can't find string terminator "'" anywhere before EOF at -e line 1.
I suppose this is due to some problem in my comprehension of " and ' in shell, but at this point, I have no idea... So if you have any tips, welcome