LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-11-2018, 03:37 AM   #1
Apostol
LQ Newbie
 
Registered: Feb 2012
Posts: 3

Rep: Reputation: Disabled
How to run commands with pipe from text file?


Hello,

I have standard loop

Code:
while read -r info; do
command $info
done < info
in info text file I have multiple commands each on line that I want to execute. When I used them in console they worked, but not with this loop. This is one of the commands in info file:

Code:
grep --line-buffered "title" dir/file.html | grep -Po '(?<=>)(.*)(?=<)'
It works with first grep, but not with second one. I found --line-buffered parameter, but didn't helped. Can somebody help me?
 
Old 03-11-2018, 04:09 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,847

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Code:
eval $info
seems ok, but it is not really suggested.
command can only execute one command, and your example contained 2 commands (2 greps)
 
1 members found this post helpful.
Old 03-11-2018, 04:53 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
If you are using PCRE, why do you need to pipe grep to grep ?.
 
Old 03-11-2018, 05:52 AM   #4
Apostol
LQ Newbie
 
Registered: Feb 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
pan64
Thank you. Eval works perfectly.

syg00
Because first I need to find line from which I want to extract information.
 
Old 03-11-2018, 09:55 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,847

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by Apostol View Post
Because first I need to find line from which I want to extract information.
This is not a reason to run two greps instead of only one. It will run faster, needs less resources and as you can see makes less difficulties too.
Most probably you can combine the two patters like:
Code:
grep -Po '(?<=title>)(.*)(?=<)'
or something similar.

A final comment: parsing a html in shell is not an easy job, probably a real html/xml parser would be better.
 
  


Reply

Tags
coding, linux, pipeline



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pipe output to append to a text file davee Linux - Newbie 5 03-22-2016 07:44 PM
Which 2 commands to run in pipe using nohup ?? techie_san778 Linux - Server 6 10-22-2013 01:49 PM
text match pipe to file then delete from original text file create new dir automatic tr1px Linux - Newbie 6 09-10-2008 09:40 PM
Run commands found in plain text file splunk Linux - Software 6 02-02-2008 11:15 AM
Pipe telnet session output to text file joshlamerritt Linux - Software 3 02-10-2004 08:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:03 AM.

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