LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


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

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


Hello

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

This works:
Code:
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:
Code:
wget -qO- 'http://www.acme.com/index.html' -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: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Try
Code:
keithhedger@severnet /tmp/xx $ wget -qO- 'http://www.acme.com/index.html' -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
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 658

Original Poster
Rep: Reputation: 35
Thanks.

I used the following successfully:
Code:
wget 'http://www.acme.com/index.html' -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.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:40 PM.

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