0

I have the following bash script that takes a text file and opens a tab in the default internet browser with a google query (after some clean ups) per line. I want to make a version of this script that works in Windows.

My question is what should I be looking at. I know windows doesn't have bash, nor sed. What is the easiest approach to this on windows?

#!/bin/bash         

URL="https://www.google.pt/?sesinv=1#output=search&q="
TMP=tmp.txt

if [ "$(uname)" == "Linux" ];then
    alias open=xdg-open
fi

sed -e '/^+++/d' -e '/^---/d' -e '/^@@/d' -e 's/^[ +-]*[0-9]* //g' $1 > $TMP

while read line         
do  
    echo "Opening $line"
    open -g "$URL$line"
done <$TMP

rm -f $TMP

2 Answers 2

1

I would use Powershell if you wanted to use a built-in solution. It can open the default browser and does some sed like functions.

0

To open a set of urls from a text file using windows commandline:

for /F "tokens=*" %a in (textFile.txt) do explorer.exe %a

in a batch script:

for /F "tokens=*" %%a in (%1) do explorer.exe %%a

(%1 is the first commandline argument.)

It doesnt take you all the way, but it ought to be enough to get you started. explorer.exe opens any file/folder passed to it in the default program.

This searches for all the lines in a txt file, not tested properly though.

for /F "tokens=*" %%A in (%1) do explorer.exe "http://www.google.com/?sesinv=1#output=search&q=%%A"
2
  • Thanks. Any suggestion for the sed bit? However I think I can Manage around it. Jun 3, 2013 at 19:41
  • Not really familiar with sed, so not sure what exactly you need, but you'll probably want to use powershell scripting (inkluded in Windows Vista and newer) with regex matching and string manipulation. Most tasks can be accomplished using batch, but Powershell is more powerful and has a more intuitive syntax.
    – Martin
    Jun 3, 2013 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .