I am trying to write a shell script which should crawl into a web page and fetch a particular character/phrase from its html and display it. Particular character means, for example if the html of the webpage contains a phrase, say password:blah, then I want to print the very next character/word to password, i.e., in short I want the script to print blah. How can I do this?

If more explanation needed, kindly ask. Thanks in advance!

  • using wget/curl and grep could work on your example but what if the html contains password:blah<br>!#foo and I want to get blah<br>!#foo ? Oct 15, 2014 at 15:46

2 Answers 2


You don't need a shell script. Probably the following compound command is what you need:

curl -s webpage | grep -Po 'password:\K\w+'

For example, the case of this page works:

curl -s http://askubuntu.com/questions/537416/copy-a-word-from-the-html-file-of-a-web-page-using-shell-script | grep -Po 'password:\K\w+'
  • Not sure that it works if the password is blah<br>!#foo. Oct 15, 2014 at 15:44
  • @SylvainPineau Unlike you, I'm sure that it not works in this case :)) . But the OP was referred to a word. Oct 15, 2014 at 16:34
  • @RaduRădeanu Could you please explain me the use of -Po and \K\w+? Oct 16, 2014 at 14:33
  • 2
    @AnanduMDas: \K only return the strings after \K (See perldoc.perl.org/perlre.html#Extended-Patterns). w+ match one or more "word" character (alphanumeric plus "_", plus other connector punctuation chars plus Unicode marks) Oct 16, 2014 at 14:33

Something like that should work:

wget -qO- http://website.com | grep -oP 'password:.*'

See man wget for all options. wget can download the whole website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.