Sprintf operator for -i and -o

Let’s say I’m making a custom axis file

$ gmt math -T1/3/1 T = | gmt convert -i+s123,+s456 | sed 's/\t/\tag\t/'
123     ag      456
246     ag      912
369     ag      1368

I want to cut the reliance on outside tools like sed, needed simply to
insert “ag” into the lines.

Perhaps a new operator should be added, maybe call it “T”(?), for -i and -o:

gmt convert -i+s123,0+Tag,+s456

But wait, why not make it a general “sprintf” operator,
so the user could also do 0+T"bla bla %.2f" to get
bla bla 123.00!

You should try to look at the gmt_io.c and gmt_api.c source code to perhaps learn that this is a no-starter. I am guessing only a handful of people would ever use something like that, hence sed is a perfect solution tor those cases.

OK, but what would be a good sed example here? Tab can’t be counted on.

I’ll add it to the gmt convert documentation.

(Too bad there is no way of simply adding a column consisting of a constant value.
Hmm, +s0 can add 0’s but then one cannot use +o to add after that because the +s and +d operations are done last. Also no way to insert ASCII A-Z…a-z…)

Adding numerical columns is not that hard:

cat > t.txt
1 2
3 4

gmt math -N3/0 t.txt -C2 5 ADD =
1 2 5
3 4 5

1 Like

(Maybe there are then even some “Bitwise String Operators” to then turn the
numbers into letters :frowning: )