Can I do this with TPIPE?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
I want to replace a line with whatever follows the (first) ampersand, like this
Code:
echo foo^&bar | tpipe <what to put here?>
bar
I gave up after about 15 minutes (mostly trying /spiit").
 
#4
Thanks, Charles. I got it to do what I want using /selection. Here's an interesting comparison. My first attempt used familiar externals and plugins. It took 3-4 minutes to compose (without needing any help).
Code:
v:\> type "http://forecast.weather.gov/MapClick.php?CityName=Syracuse&state=NY&site=BGM&textField1=43.0446&textField2=-76.1459&e=0" | egrep "point-fore.*High|point-fore.*Low" | notags| cut -d"&" -f1 | tr -s " " " " | sed 's/Low: /Low:  /g'
 High: 27
 Low:  10
 High: 30
 Low:  23
 High: 31
 Low:  21
 High: 33
 Low:  20
 High: 32
After more than an hour's work (and some forum help) I did it with tpipe alone.
Code:
v:\> type "http://forecast.weather.gov/MapClick.php?CityName=Syracuse&state=NY&site=BGM&textField1=43.0446&textField2=-76.1459&e=0" | tpipe /grep=3,0,0,1,0,0,0,0,"point-fore.*High|point-fore.*Low" /simple=16 /selection=7,0,2,2,0,5,"&",0 /simple=19 /replace=0,1,0,1,0,0,0,0,0,"Low: ","Low:  "
High: 27
Low:  10
High: 30
Low:  23
High: 31
Low:  21
High: 33
Low:  20
High: 32
When used on a local copy of the file, TPIPE gets the job done in one third the time. I'm not sure it was worth it. If I had used TPIPE as long as I have used EGREP, TR, and SED, I'd still have to go to the docs.

The bottom line is it's going to be cold tonight!

I know the user can save TPIPE filters, but I have never done it. It would be nice if the more familiar text utills (or specific uses of them) could have short TPIPE versions, with replaceable parameters, and which could be strung together. For example, if I had (somehow) defined "/squeeze" to act like TR.EXE -s, and /cut to act like CUT.EXE, then instead of

Code:
type file | tr -s " " " " | cut -d " " -f2-5 (squeeze spaces and pick space-delimited columns 2-5)
I could

Code:
type file | tpipe /squeeze=" " /cut=" ",2,5
 
#5
Another question. "/simple=19" squeezes whitespace. But suppose I want to squeeze multiple occurrences of any specific character into a single occurrence?

Code:
tpipe /replace=0,1,0,0,0,0,0,0,0,"xx","x"
will turn 2N x's into N of them, and

Code:
/replace=4,1,0,0,0,0,0,0,0,x*,x
does nothing (apparently it's not "greedy", not looking for the longest matching target string).

And I have no idea what's happening in this one; it seems completely wrong.
Code:
v:\> echo fooxxxxxxxxbar | tpipe /replace=4,1,0,0,0,0,0,0,0,"x.a*","Z"
fooZZZZbar
I meant to replace the (Perl) pattern "x.a*" with "Z" (expecting "fooxxxxxxxZr"). Can anyone make sense of what actually happened?
 
#6
Rex, do you build TEXTPIPEENGINE.DLL? If so, do you use "PCRE_UNGREEDY"?

Perl quantifiers are, by default, greedy (find the longest match). But it's not so in TPIPE.
Code:
g:\tc14> echo fooxxxxxxxxbar | tpipe /replace=4,1,0,0,0,0,0,0,0,x+,z
foozzzzzzzzbar
According to the TextPipeEngine docs, greediness can be reversed, as in
Code:
g:\tc14> echo fooxxxxxxxxbar | tpipe /replace=4,1,0,0,0,0,0,0,0,x+?,z
foozbar
But (IMHO) greediness should be the default.