1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can I do this with TPIPE?

Discussion in 'Support' started by vefatica, Jan 2, 2013.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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").
     
  2. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,177
    Likes Received:
    11
    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,&]]]
    
     
  3. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    Maybe something like this?

    Code:
    echo foo^&bar^&baz | tpipe /selection=7,0,1,1,0,5,"&",0
    
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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.
     
  7. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,726
    Likes Received:
    80
    No.
     
  8. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    From what I gleaned from the DataMystic docs, ungreedy Perl regular expressions should not be the default. Yet they seem to be so. Perhaps you'd ask the developers about that.
     
  9. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,726
    Likes Received:
    80
    According to the DataMystic docs for the textpipe engine, ungreedy Perl regular expressions *are* the default.
     

Share This Page