Can I do this with TPIPE?

May 20, 2008
11,400
99
Syracuse, NY, USA
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").
 

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
It is easy enough to do using the other built-in functions.
Code:
set foo=foo^&bar
setdos /x-5
echo %@substr[%foo,%@inc[%@index[%foo,&]]]
 
May 20, 2008
11,400
99
Syracuse, NY, USA
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
 
May 20, 2008
11,400
99
Syracuse, NY, USA
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?
 
May 20, 2008
11,400
99
Syracuse, NY, USA
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.
 
Similar threads
Thread starter Title Forum Replies Date
samintz How to? TPIPE /simple=61 Support 6
R Bug TPIPE's pdf to text conversions don't work Support 2
Kachupp How to? tpipe Support 4
H TPIPE /simple=4 Support 12
D TPIPE produces unwanted logs. Support 1
Kachupp How to? tpipe Support 8
vefatica Documentation TPIPE, /perl, DotMatchesNewLines Support 1
vefatica Stop TPIPE /EOL removing bad EOLs (and TPIPE changine EOLs)? Support 2
vefatica TPIPE in an alias? Support 2
C How to? TPIPE ?'s Support 2
H History and TPipe Oddness Support 3
Jay Sage Baffling Behavior With TPIPE Support 5
vefatica TPIPE: unbalanced escaped quotes in a regex? Support 5
Joe Caverly Multiple Text Searches at once using FFIND or TPIPE Support 4
Kachupp FFIND TPIPE Support 9
vefatica TPIPE and avarice? Support 5
Peter Murschall TPIPE generate unicode on Piping or redirecting Support 3
x13 TPIPE /REPLACE - Remove line (including EOL) Support 3
Charles Dye Documentation TPIPE /REPLACELIST Support 0
Joe Caverly TPIPE and /inputstring Support 3
vefatica How to? Add real <ESC> characters with TPIPE Support 2
vefatica How to? TPIPE ... see output right away? Support 4
vefatica TPIPE.EXE crashes on Ctrl-C Support 9
O TPIPE: Error -Can´t access textpipeengine.dll Support 24
vefatica Extract fields with TPIPE? Support 10
vefatica TPIPE, crash and question Support 1
MickeyF Another TPIPE question Support 6
MickeyF Can't get my TPIPE /replace to work Support 4
Joe Caverly Printing TPIPE documentation Support 3
C WAD tpipe /simple=28 Support 8
vefatica Remove double-quotes with TPIPE Support 4
vefatica TPIPE crashes on Ctrl-C Support 1
C How to? Add date/time to custom tpipe based BTM Support 1
C tpipe /simple=28 error Support 5
C TPipe /dup Support 5
T TPipe: Replacing String with Double Quotes Support 3
C tpipe and extract email addresses Support 1
vefatica How do I do this with TPIPE? Support 1
vefatica TPIPE's /perl option? Support 1
D TPIPE help typo Support 0
vefatica TPIPE access violations are back Support 2
Joe Caverly Word Count using TPIPE Support 10
Dan Glynhampton TPIPE in Build 41 Support 4
Phileosophos TPIPE doesn't work at all with v16 Support 3
vefatica TPIPE access violation again Support 1
David McClelland TPIPE matching problem Support 3
vefatica TPIPE: Access violation Support 5
jbanaszczyk TCMD 16 - TPIPE Support 4
P TPipe relaunches TCC window and 4start, etc Support 7
Phileosophos Documentation TPIPE /string type code confusion Support 4

Similar threads