Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 06-05-2015, 04:57 PM   #1
Registered: Aug 2008
Location: France
Posts: 652

Rep: Reputation: 35
Question Grep doesn't read stdin?


I'm no regex/grep expert, and having a bit of a problem getting grep to read data from stdin.

This works:
grep -Pzo "(?s)(?<=<title>\n)(.*)(?=</title>)" input.html
This prints nothing, although the Internet says that grep reads stdin unless told to read from a file:
wget -qO- '' -so - | grep -Pzo "(?s)(?<=<title>)(.*)(?=</title>)"
Any idea why?

FWIW, it's GNU grep 2.12 running on Debian.

Thank you.
Old 06-05-2015, 06:03 PM   #2
Keith Hedger
Senior Member
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 3,073

Rep: Reputation: 832Reputation: 832Reputation: 832Reputation: 832Reputation: 832Reputation: 832Reputation: 832
keithhedger@severnet /tmp/xx $ wget -qO- '' -O - | grep -Pzo "(?s)(?<=<title>)(.*)(?=</title>)"
ACME Laboratories
There is no 's' option and it should be a capital 'O' to set the output file name.
1 members found this post helpful.
Old 06-10-2015, 08:06 AM   #3
Registered: Aug 2008
Location: France
Posts: 652

Original Poster
Rep: Reputation: 35

I used the following successfully:
wget '' -qO - | grep -Pzo '(?s)(?<=<title>)(.*)(?=</title>)' > output.html
The "(?s)" option is to tell grep to support multine mode, while "(?<=" and "(?=" is so that those bits between brackets are ignored in the output.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell Read(Stdin) Loop Making Me Nuts Luridis Programming 11 04-14-2014 02:19 PM
[SOLVED] Read from stdin in man? dansimon Linux - General 6 06-18-2013 02:56 AM
[SOLVED] Read from stdin in perl, do not wait for EOF smeezekitty Programming 1 04-28-2010 03:17 PM
read from stdin in a shell script bujecas Linux - General 3 07-03-2009 04:46 PM
after redirecting stdin still need to read data from keyboard vrikers Programming 4 10-31-2004 06:11 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:53 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration