1.

Solve : How to search & replace a string in text file using a batch file?

Answer» <html><body><p>....<br/><br/> Quote</p><blockquote>Does it mean: In string1, replace 'Mary' with 'Peter, Paul and Mary' and then <a href="https://interviewquestions.tuteehub.com/tag/put-11868" style="font-weight:bold;" target="_blank" title="Click to know more about PUT">PUT</a> that in string <a href="https://interviewquestions.tuteehub.com/tag/5-237653" style="font-weight:bold;" target="_blank" title="Click to know more about 5">5</a>, and then, in the resulting string 5, replace 'lamb' with 'lamb each'?</blockquote> <br/>Yes, that's exactly right. I could have used a single ampersand (command1 &amp; command2 means 'do command 1 and then do command 2") but I am in the habit from Unix/Linux of using &amp;&amp; - (command1 &amp;&amp; command2 means 'do command1 and if it is successful do command2'). Works the same in Windows.<br/><br/>They could just as easily have been on two lines like this, I guess I wanted to show what you can do on one line.<br/><br/>set string5=%string1:Mary=Peter, Paul and Mary%<br/>set string5=%string5:lamb=lamb each% <br/> Quote from: Salmon Trout on November 18, 2019, 11:38:46 AM<blockquote>That VBScript has a feature I don't like. It overwrites the input file.<br/></blockquote> Yes, that is by design.<br/><br/> Quote<blockquote>As for Question 1, you can place a one-line batch script in your Startup folder<br/><br/>cscript //nologo path/to/scriptname.vbs<br/></blockquote> What does ' //nologo' do?<br/><br/> Quote<blockquote>If you code the actual paths to the input and output .txt files in the script, you can put the .vbs script itself in the Startup folder.</blockquote> I've tried that, it's unsure if that works. <br/><br/> Quote<blockquote>This all looks a bit shaky though. If this is corporate data in a work setting, should you be doing this?<br/></blockquote> No, it's just about a multiboot situation where Win10 was installed later, and thus, changes the "D-station" to a "C-station". Home stuff. Corporate, I wish. Not savvy enough for that. <br/>Thanks Salmon for your efforts.<br/>Do you know the Salmon song?<br/>"Salmon, Salmon, Salmon,<br/>You're so delicious<br/>I love you more<br/>than all the other fishes" Quote from: Salmon Trout on November 18, 2019, 11:38:46 AM<blockquote>If you code the actual paths to the input and output .txt files in the script, you can put the .vbs script itself in the Startup folder.</blockquote> <br/>I've tried it out now and it doesn't work.<br/><br/><br/>The Startup folder I use is this one:<br/>C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\<br/><br/>And:<br/>D:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\<br/><br/><br/>If I put the .vbs file into these folders, how do I ensure that they are actually executed on start up? <br/>Excuting them manually is no problem Quote from: H4ckRn00b on November 18, 2019, 11:51:18 AM<blockquote>What does ' //nologo' do?</blockquote> <br/>There are two 'script engines' in Windows, cscript.exe and wscript.exe. The cscript engine uses a console window to run a script. This means you can have lines of text output that you can read all at once. By default it shows a text 'logo' like this at the start of a script:<br/><br/>C:\Users\Mike&gt;cscript //logo test.vbs<br/>Microsoft (R) Windows Script Host Version 5.812<br/>Copyright (C) Microsoft Corporation. All rights reserved.<br/><br/>Hello World<br/><br/>The //nologo switch gives just the script output<br/><br/>C:\Users\Mike&gt;cscript //nologo test.vbs<br/>Hello World<br/><br/>This is test.vbs by the way<br/><br/>wscript.echo "Hello World"<br/><br/>The wscript.exe engine does not show a console window, and emits any output using message boxes (one for each wscript.echo statement, and you have to click OK with the mouse). You don't have to worry about a 'logo'. <br/><br/><br/><br/> Quote<blockquote>I've tried that, it's unsure if that works.</blockquote> <br/>Can't you check?<br/><br/> Quote<blockquote>Do you know the Salmon song?</blockquote> <br/>I like that song. However, I am named after a steam railway locomotive, London and North Eastern Railway No. 2506 <em>Salmon Trout</em> later renumbered to 60041 by British Railways in 1948. The loco was a member of a class all named after famous racehorses, so that's where it started.<br/><br/><br/>I think this is a candidate for  'Thread of the Month' !  Quote from: Geek-9pm on November 18, 2019, 03:53:59 PM<blockquote>I think this is a candidate for  'Thread of the Month' !  <br/></blockquote> to quote 10 year old <strong>Ben </strong>from <a href="https://www.imdb.com/title/tt1086191/reference"><em>"Outnumbered (2007)"</em></a>: ............."Sarcasm!" Quote from: Salmon Trout on November 18, 2019, 12:46:16 PM<blockquote>Can't you check?</blockquote> I did. Now, after several tries &amp; <a href="https://interviewquestions.tuteehub.com/tag/reboots-7324588" style="font-weight:bold;" target="_blank" title="Click to know more about REBOOTS">REBOOTS</a>, I <a href="https://interviewquestions.tuteehub.com/tag/got-23540" style="font-weight:bold;" target="_blank" title="Click to know more about GOT">GOT</a> it right. Joy. Yah. I can give you the full script and .... context, but I'm not sure that'd be interesting to you.<br/><br/> Quote<blockquote>(...)later renumbered to 60041 by British Railways in 1948. (...) </blockquote> Oooooooh..... hobby's showing!   obsessive, a bit?  Pure dedication, I'm sure....   &lt;3 <br/> Quote<blockquote> (...)named after famous racehorses, (...)<br/></blockquote> Locs with fish names, named after horses ...... Ya can't get more British than that! &lt;3</body></html>


Discussion

No Comment Found