|
Answer» So I started to really use repl, and It's made quite a few of my scripts run infinitely smoother. I'm running into some issues though. I'm attempting to gather Lat / Long coordinates from a .kml file (looks quite a lot like html to me). The issue that I've run into is that all the data in the kml is on the first line. to correct this, I was trying to use repl to add new line characters at specific places to allow me to gather the necessary information using a for loop. But for some reason, repl is erroring when I try.
Code: [Select]T:\job>type "Cars French 1.kml" | repl X I "<address^>" "\n<address^>" >[f].txt The syntax of the command is incorrect. The syntax of the command is incorrect. C:\cmdPlugins\repl.bat(191, 1) Microsoft JScript runtime error: Syntax error in regular expression
The process tried to write to a nonexistent pipe.
T:\job>type "Cars French 1.kml" | repl X I "<address>" "\n<address>" >[f].txt | was unexpected at this time. The process tried to write to a nonexistent pipe.
Code: (Example kml) [Select]<?xml version="1.0"?><kml xmlns="http://earth.google.com/kml/2.0"><Document><name>Stuff</name><description> | Created with http://batchgeo.com</description><style id="0"><BalloonStyle><text><![CDATA[ <b>$[name]</b><br />$[address]<br />$[description]<br/><br/>$[geDirections] ]]></text></BalloonStyle></style><Placemark><name>Amerya (3S)</name><description><div><span class="l">Phone:</span>&nbsp;(+2)034700165 </div></description><Point><coordinates>29.918739595939,31.20009469878,0</coordinates></Point><address>24kM Cairo-Alex Desert Road Alexandria Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Amex Ragheb</name><description><div><span class="l">Phone:</span>&nbsp;(+2)01222101673 </div></description><Point><coordinates>32.687635261674,25.680906223415,0</coordinates></Point><address>Airport Road Luxor Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Anas lel Sayarat</name><description><div><span class="l">Phone:</span>&nbsp;(+2)01003422839</div></description><Point><coordinates>32.899830632474,24.088942749132,0</coordinates></Point><address>El Mante 2a El Senaeya El gedida Aswan Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Ara Mechanics</name><description><div><span class="l">Phone:</span>&nbsp;(+2)01111099909</div></description><Point><coordinates>31.340403435549,30.089174843937,0</coordinates></Point><address>48 Abdel Razik El Sanhory St. From Makram Ebid Madinet Nasr Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Arish (2S)</name><description><div><span class="l">Phone:</span>&nbsp;(+2)0683353853</div></description><Point><coordinates>33.80327807662,31.132096531236,0</coordinates></Point><address>El Farik Bahary Fouad Zikry St. Behind Samiramis Hotel Arish Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Asyut (Service Center)</name><description><div><span class="l">Phone:</span>&nbsp;(+2)0882289663</div></description><Point><coordinates>31.185925714141,27.178313572373,0</coordinates></Point><address>El Wady El Gedeed Desert Road Infront of El Manteaa El Ganobeya el askareya Asyut Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Asyut (2S)</name><description><div><span class="l">Phone:</span>&nbsp;(+2)0882289663</div></description><Point><coordinates>31.174390102815,27.195572765047,0</coordinates></Point><address>55 ElHelaly St. Asyut Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Auto Group</name><description><div><span class="l">Phone:</span>&nbsp;(+2)16441</div></description><Point><coordinates>31.205026080241,30.050752011337,0</coordinates></Point><address>26 El Nakhil Street Mohandsein Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Auto Group</name><description><div><span class="l">Phone:</span>&nbsp;(+2)16441</div></description><Point><coordinates>29.926686437909,31.198941618085,0</coordinates></Point><address>27 Hassan lbn Thabet Tanta Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Dokki Showroom</name><description><div><span class="l">Area:</span>&nbsp;Dokki</div><div><span class="l">Short Number:</span>&nbsp;12311</div><div><span class="l">Phone:</span>&nbsp;(+2)33388463/7</div></description><Point><coordinates>31.204727306108,30.043222977757,0</coordinates></Point><address>40 Nadi EL Sayd St Giza Egypt</address><styleUrl>#0</styleUrl></Placemark><Placemark><name>Dokki Spareparts</name><description><div><span class="l">Short Number:</span>&nbsp;12311</div><div><span class="l">Phone:</span>&nbsp;(+2)33358686</div></description><Point><coordinates>31.21457336134,30.042570120257,0</coordinates></Point> There's new version of repl.bat out which adds an extra N option to handle files with NULL characters correctly.
`repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
This ADDRESSES your error - there's no need to escape the > inside the quotes.
Code: [Select]type "Cars French 1.kml" | repl "<address>" "\n<address>" xi >file.txt and you might find this better for your usage:
Code: [Select]type "Cars French 1.kml" | repl "(</.*?>)" "$1\n" xi >file.txtI'm getting a "A device attached to the system is not functioning." error at lines 300 and 305. Both at occurring when the script tries to run "WScript.Stdout.WriteLine(...)". Any ideas?
Code: (Didn't WORK) [Select]type 1.kml | repl "address" "2address" mn type 1.kml | repl "address" "\naddress" mxin type 1.kml | repl "<address>" "\n<address>" mxin type 1.kml | repl "<address>" "\n<address>" xin
Both 'type "Cars French 1.kml" | repl "()" "$1\n" xi >file.txt' and 'type "Cars French 1.kml" | repl "
" "\n
" xi >file.txt' returned files, but did not add the newline character.
EDIT: The last one added the newline char, but it only appears when viewing from preview in explorer.exe EDIT 2: I managed to get it to work, but would still like to learn whats wrong.
Quote from: Lemonilla on July 28, 2014, 10:03:14 AM Both 'type "Cars French 1.kml" | repl "(</.*?>)" "$1\n" xi >file.txt' and 'type "Cars French 1.kml" | repl "<address>" "\n<address>" xi >file.txt' returned files, but did not add the newline character.
Yes, they do, but they don't add a CR and LF as I assumed you had a reason for using \n alone.
Change \n to \r\n and it will use normal Windows line endings.
Look at the output files in Winhex and you will see the 0A which is the \n character.
0A is the DEFAULT line ending character for Unix/Linux, and Windows uses 0D 0A as the line ending characters, a Carriage Return and then a Line feed. The 0D is added by the \r in repl.
In an Apple system the line ending is just a 0D or it used to be.
The 0D 0A is hexadecimal notation for anyone not sure, and is shown as 13 10 in decimal ascii.Thanks, I didn't know that.
|