setting a variable variable in a script... this works, but could it be more elegant?
Hello everyone,
For my research project I have to plot a lot of graphs. We use a software package called Generic Mapping Tools (GMT) for this, where you create csh scripts which call a number of gmt programs which plot to postscript files. I've created a script which uses a foreach loop to plot a number of graphs (about 50 in total) which creates certain variables each time the loop runs. For each iteration, the command I want people's opinions on calculates the minimum and maximum value of a number of columns for each individual input file. Each input file looks something like this: Code:
Eastings: Northings: Depth: Distance Along Line: Spacing: Code:
3d_dunes_001_ns.dat: N = 645 <581294/581320> <92609.9/93871.7> <-31.8896/-28.7709> <0/1262.05> <1/1> Code:
0/1262.05/-31.8896/-28.7709 Code:
set plot_area=-R`cat 3d_dunes_001_ns.dat | minmax | tr "/" " " | tr "<" " " | tr ">" " " | awk '{printf "%1d %4d %2d %2d\n", $12,($13+50),($10-2),($11+2)}' | tr " " "/"` So basically, I would like to know if there's a more elegant way of getting rid of the '<','>' and '/' without using 3 tr's? Thanks :) |
You could use a single tr:
Code:
ada@barnabas:~> echo "a<b>c|d" | tr "<>|" " " |
Holy unreadable pipelines Batman! This is a job for.... Perl!
Code:
perl -wne 's/^.*?<([^>]+)>\s+<([^>]+)>\s+<[^>]+>\s*$/$2 $1/&&print' <input file> |
heh! this is my most recent monster command (can't be bothered to put it into a script, so just run it as is from the cli):
Code:
set input = raw_data/bank_parallel_002.dat && set minmax = -36/-33 && awk '{print $4, $3}' $input | psxy -JX15/3 -R0/400/$minmax -Ba200g100/a1g0.5 -Xc -Y25 -P -K > test.ps && awk '{print $4, $3}' $input | psxy -JX15/3 -R400/800/$minmax -Ba200g100/a1g0.5 -Y-6 -P -O -K >> test.ps && awk '{print $4, $3}' $input | psxy -JX15/3 -R800/1200/$minmax -Ba200g100/a1g0.5 -Y-6 -P -O -K >> test.ps && awk '{print $4, $3}' $input | psxy -JX15/3 -R1200/1400/$minmax -Ba200g100/a1g0.5 -Y-6 -P -O -K >> test.ps && gs -sPAPERSIZE=a4 test.ps |
All times are GMT -5. The time now is 05:00 AM. |