I’m having some trouble with getting this to do what I want it to do.
read -p "URL to read: " U read -p "Word to fin: " O read -p "Filename: " F curl -O $U | sed "s/<$O>/*$O*/g" > $F.txt
So basically what I want is to use curl
to get a .txt
file from a url, then sort through it to find the word specified by the user input. Then mark all those words with a *
and put them in a file specified by the user.
Almost the exact same code works in Linux, but this doesn’t work on my Mac. Anyone got an idea?
Advertisement
Answer
Two issues:
-O
makescurl
store the downloaded file, not output it onstdout
.- word boundary metacharacters
<
and>
are a GNU extension. On BSDsed
, you can use[[:<:]]
and[[:>:]]
instead.
This should work on OSX:
curl "$U" | sed "s/[[:<:]]$O[[:>:]]/*$O*/g" > $F.txt