Welcome!

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

SignUp Now!

For those wanting to learn TPIPE...

Aug
1,916
68
This is in response to Bob Chapman, and his wanting to learn more about TPIPE.

Take a read of http://jpsoft.com/forums/threads/delete-a-line-from-a-file.4961/#post-28369

I would never have thought to use TPIPE to solve my problem, if Rex had not pointed me in the proper direction.

I guess the best way to learn is to present your problem here on the forums, and see what response you get.

For example, I would like to get a list of the URLs in the FireFox sessionstore.js file. I presently do this using a combination of TCC and BASH;

Code:
@setlocal
@echo off
cd %appdata
set thefile=%@execstr[dir sessionstore.js /s/b]
iff exist %@quote[%thefile] then
  if exist c:\utils\sessionstore.js del c:\utils\sessionstore.js
  if exist c:\utils\results.txt? del c:\utils\results.txt?
  copy %@quote[%thefile] c:\utils
  cd c:\cygwin\bin
  bash --login "c:\utils\urls.sh"
  cd c:\utils
  dir /[d-0]
  if exist c:\utils\results.txt? call listc.btm results.txt?
  if exist c:\utils\sessionstore.js del c:\utils\sessionstore.js
  if exist c:\utils\results.txt? del c:\utils\results.txt?
else
  echo The sessionstore.js file does not exist.
endiff
endlocal

Code:
#!/bin
sed -e 's/{"url":/\n&/g' /cygdrive/c/utils/sessionstore.js | cut -d\" -f4 > /cygdrive/c/utils/results.txt

Not very elegant, but it does what I want it to do.

If I could figure out how to replace the urls.sh BASH script with TPIPE, that would be great. Not really sure where to start with TPIPE, though, to accomplish this. I find the help for TPIPE to be overwhelming, mainly due to my declining eyesight, and the lack of TPIPE examples.

Joe
 
Joe - Thanks for the response and the reference. As I noted in my reply to Vince <tpipe and MSVCR110.dll TCC x64 Build 44??>, my primary mistake has been an attempt to devour the whole elephant in one bite instead of a piece at a time! ;) That being said, I have to agree with your assessment of the help for tpipe -- and my eyesight is relatively good!
 
If I could figure out how to replace the urls.sh BASH script with TPIPE, that would be great. Not really sure where to start with TPIPE, though, to accomplish this. I find the help for TPIPE to be overwhelming, mainly due to my declining eyesight, and the lack of TPIPE examples.

Joe

I am one step closer. The following TPIPE command replaces {"url": with a newline;

Code:
  tpipe /input=sessionstore.js /output=sessionstore.txt /replace=0,0,0,0,0,0,0,0,0,%@quote[{"url":],\n

Joe
 
Here's a non-trivial example (excerpted from a BTM file).
Code:
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:  "
You should be able to paste that right onto a TCC command line and see:
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: 45
Low:  40
High: 61
Low:  42
High: 65
Low:  42
High: 71
Low:  47
High: 75
 
I am not familiar with sed, so I don't understand what your script is doing. If the goal is to pick out the lines beginning with {"url": and display them without the URL: preface, why can't you use FFIND and @right[]?
Code:
do url in /p ffind /k /m /v /t"{^"url^":" sessionstore.js (echo %@right[-7,%url])
 
I am not familiar with sed, so I don't understand what your script is doing. If the goal is to pick out the lines beginning with {"url": and display them without the URL: preface, why can't you use FFIND and @right[]?
Code:
do url in /p ffind /k /m /v /t"{^"url^":" sessionstore.js (echo %@right[-7,%url])

The sessionstore.js is one continuous long line, with a file size of (for this FireFox session) of 8,466 bytes, which is why I am replacing the {"url": with a newline. Here's a clip of my current sessionstore.js;

Code:
[{"url":"http://jpsoft.com/forums/find-new/45243/threads","title":"Recent Threads | Take Command Windows command processor","ID":10,"docshellID":12,"docI
dentifier":10},{"url":"http://jpsoft.com/forums/threads/for-those-wanting-to-learn-tpipe.5008/","title":"For those wanting to learn TPIPE... | Take Command Windows com
mand processor","ID":21,"docshellID":12,"referrer":"http://jpsoft.com/forums/threads/for-those-wanting-to-learn-tpipe.5008/","docIdentifier":21,"scroll":"0,2306"}],"in
dex":2,"hidden":false,"attributes":{"image":"http://jpsoft.com/favicon.ico"},"storage":{"http://jpsoft.com":{"quickReplyText":"<p>[quote=&quot;samintz, post: 28641, me
mber: 8&quot;]I am not familiar with sed, so I don't understand what your script is doing.  If the goal is to pick out the lines beginning with {&quot;url&quot;: and d
isplay them without the URL: preface, why can't you use FFIND and @right[]?</p>\n<p>[code]</p>\n<p>do url in /p ffind /k /m /v /t&quot;{^&quot;url^&quot;:&quot; sessio
nstore.js (echo %@right[-7,%url])</p>\n<p>
[/quote]</p>\n<p><br /></p>"}}}],"selected":3,"_closedTabs":[{"state":{"entries":[{"url":"http://www.curtrenz.com/occu
ltations","title":"Occultations","ID":13,"docshellID":15,"referrer":"http://www.powerbasic.com/support/pbforums/showthread.php?t=52956","docIdentifier":13,"scroll":"0,
0"}],"index":1,"hidden":false,"attributes":{}},"title":"Occultations","image":"","pos":3},{"state":{"entries":[{"url":"http://www.powerbasic.com/support/pbforums/showt
hread.php?t=52956","title":"Big Bright Full Moon ΓÇô Occultation ΓÇô Eclipse ΓÇô May 24 - PowerBASIC Peer Support Forums","ID":12,"docshellID":14,"referrer":"http://ww
w.powerbasic.com/support/pbforums/search.php?s=a286a9287b4410a7c65920c520b55649&searchid=270247","docIdentifier":12,"formdata":{"id":{},"xpath":{"/xhtml:html/xhtml:bod
y/xhtml:div[3]/xhtml:div/xhtml:div/xhtml:table[2]/xhtml:tbody/xhtml:tr/xhtml:td[2]/xhtml:table/xhtml:tbody/xhtml:tr/xhtml:td/xhtml:div/xhtml:form/xhtml:select[@name='f
']":{"selectedIndex":29,"value":"17"}}},"scroll":"0,0"}],"index":1,"hidden":false,"attributes":{"image":"http://www.powerbasic.com/favicon.ico"}},"title":"Big Bright F
ull Moon ΓÇô Occultation ΓÇô Eclipse ΓÇô May 24 - PowerBASIC Peer Support Forums","image":"http://www.powerbasic.com/favicon.ico","pos":3},{"state":{"entries":[/CODE]

(Due to the tags in the file, the above did not paste properly into this forum message.)

Using the TPIPE command, that gives me (again, just a clip);


Code:
"http://jpsoft.com/forums/find-new/45243/threads","title":"Recent Threads | Take Command Windows command processor","ID":10,"docshellID":12,"docIdentifier":10},
"http://jpsoft.com/forums/threads/for-those-wanting-to-learn-tpipe.5008/","title":"For those wanting to learn TPIPE... | Take Command Windows command processor","ID":2
"http://www.curtrenz.com/occultations","title":"Occultations","ID":13,"docshellID":15,"referrer":"http://www.powerbasic.com/support/pbforums/showthread.php?t=52956","d
"http://www.powerbasic.com/support/pbforums/showthread.php?t=52956","title":"Big Bright Full Moon ΓÇô Occultation ΓÇô Eclipse ΓÇô May 24 - PowerBASIC Peer Support Foru
"http://www.powerbasic.com/support/pbforums/search.php?s=a286a9287b4410a7c65920c520b55649&searchid=270247","title":"PowerBASIC Peer Support Forums - Search Results","I

which leaves me only to clip off everything after the URL, so that I have;

"http://jpsoft.com/forums/find-new/45243/threads"
"http://jpsoft.com/forums/threads/for-those-wanting-to-learn-tpipe.5008/"
"http://www.curtrenz.com/occultations"
"http://www.powerbasic.com/support/pbforums/showthread.php?t=52956"
"http://www.powerbasic.com/support/p...6a9287b4410a7c65920c520b55649&searchid=270247"

cut -d\" -f4 clips off everything after the URL in BASH, so I just have to figure out how to do this with TPIPE.

Joe
 
Another non-trivial TPIPE example.
Code:
type http://w1.weather.gov/data/obhistory/KSYR.html ^
| tpipe ^
/grep=3,0,0,1,0,0,0,0,"right.*left" ^
/replace=4,1,0,1,0,0,0,0,0,".*([0-9][0-9]:[0-9][0-9]).*td.(-*[0-9]*)..td..td.*[0-9]*..td.$","$1  $2" ^
/head=0,0,24
It gives the temperatures (at KSYR) for the last 24 hours. It's noticeable faster that the equivalent "type ... | grep ... | sed ... | head ...".
Code:
14:54  45
13:54  44
12:54  42
11:54  42
10:54  42
09:54  43
08:54  44
07:54  44
06:54  44
05:54  44
04:54  44
03:54  45
02:54  46
01:54  48
00:54  50
23:54  53
22:54  58
21:54  64
20:54  65
19:54  66
18:54  66
17:54  68
16:54  68
15:54  65
 
Joe - try this

Code:
/selection=7,3,2,0,0,0,"",0,0

Dan

Hello Dan,
I tried it, and it does what I require it to do. Here is my revised batch file, with the call to the BASH script replaced with TPIPE;


Code:
@setlocal
@echo off
cd %appdata
set thefile=%@execstr[dir sessionstore.js /s/b]
iff exist %@quote[%thefile] then
  if exist c:\utils\sessionstore.js del c:\utils\sessionstore.js
  if exist c:\utils\sessionstore.txt del c:\utils\sessionstore.txt
  copy %@quote[%thefile] c:\utils
  cd c:\utils
  tpipe /input=sessionstore.js /output=sessionstore.txt /replace=0,0,0,0,0,0,0,0,0,%@quote[{"url":],\n /selection=7,3,2,0,0,0,"",0,0
  if exist c:\utils\sessionstore.txt call listc.btm sessionstore.txt
  if exist c:\utils\sessionstore.txt del c:\utils\sessionstore.txt
  if exist c:\utils\sessionstore.js del c:\utils\sessionstore.js
else
  echo The sessionstore.js file does not exist.
endiff
endlocal

Many thanks!

Joe
 
Joe, you could just pipe the whole thing into VIEW and then you wouldn't need all those delete statements.
Code:
tpipe /input="%@execstr[dir sessionstore.js /s/b]" /replace=0,0,0,0,0,0,0,0,0,%@quote[{"url":],\n /selection=7,3,2,0,0,0,"",0,0 | VIEW
 
Joe, you could just pipe the whole thing into VIEW and then you wouldn't need all those delete statements.
Code:
tpipe /input="%@execstr[dir sessionstore.js /s/b]" /replace=0,0,0,0,0,0,0,0,0,%@quote[{"url":],\n /selection=7,3,2,0,0,0,"",0,0 | VIEW

Thankyou Scott.

Joe
 
Joe, you could just pipe the whole thing into VIEW and then you wouldn't need all those delete statements.
Code:
tpipe /input="%@execstr[dir sessionstore.js /s/b]" /replace=0,0,0,0,0,0,0,0,0,%@quote[{"url":],\n /selection=7,3,2,0,0,0,"",0,0 | VIEW


Scott's contraction of the solution to a single line makes it an excellent candidate for an alias rather than a batch file:

Code:
alias sites=`tpipe /input="%@execstr[dir sessionstore.js /s/b]" /replace=0,0,0,0,0,0,0,0,0,%@quote[{"url":],\n /selection=7,3,2,0,0,0,"",0,0 | VIEW`

You don't have to call it "sites" of course, but you get the idea...

Dan
 
Back
Top