Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

TPIPE in an alias?

May
12,834
163
I want to 0-pad months and days in the likes of m/d/yyyy (as is output by the ancient DUMPEL.EXE). TPIPE can do that.
Code:
v:\> echo 1/1/2020 1/2 | tpipe /replace=4,0,0,0,0,0,0,0,0,"^(\d)/",0$1/ /replace=4,0,0,0,0,0,0,0,0,"/(\d)/","/0$1/"
01/01/2020 1/2

That is: pad a single digit between BOL and a forward slash, then pad a single digit between two forward slashes.

But it behaves differently if I put theTPIPE command into an alias.
Code:
v:\> alias fixdates `tpipe /replace=4,0,0,0,0,0,0,0,0,"^(\d)/",0$1/ /replace=4,0,0,0,0,0,0,0,0,"/(\d)/","/0$1/"`

v:\> echo 1/1/2020 1/2 | fixdates
01/01/2020 01/2

In this case, TPIPE seems to be ignoring the first '/' in the search criterion, "/(\d)/", of the second replacement.

Are there any conjectures on why this happens and/or how to fix it?
 
I think I figured it out. I had thought that '^' (to indicate BOL in a regex) was left alone inside double quotes. But that's not so in the making of an alias.

Code:
v:\> alias foo `echo "^"`

v:\> alias foo
echo ""

Is that WAD?

So. to fix my original problem, double the '^' in the alias definition.

Code:
v:\> alias fixdates `tpipe /replace=4,0,0,0,0,0,0,0,0,"^^(\d)/",0$1/ /replace=4,0,0,0,0,0,0,0,0,"/(\d)/","/0$1/"`

v:\> echo 1/1/2020 1/2 | fixdates
01/01/2020 1/2
 

Similar threads

Back
Top