Linux

RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

How to run commands with pipe from text file?

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-11-2018
adamlevine adamlevine is offline
Banned
 
Join Date: Mar 2018
Last Activity: 4 June 2018, 5:31 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
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?
Moderator's Comments:
How to run commands with pipe from text file? Please use CODE tags when displaying sample input, sample output, and code segments.

Last edited by Don Cragun; 03-11-2018 at 09:37 PM.. Reason: Add CODE and ICODE tags.
Sponsored Links
    #2  
Old 03-11-2018
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 18 July 2018, 5:02 AM EDT
Location: San Jose, CA, USA
Posts: 11,407
Thanks: 649
Thanked 3,970 Times in 3,393 Posts
Quote:
Originally Posted by adamlevine View Post
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?
Moderator's Comments:
How to run commands with pipe from text file? Please use CODE tags when displaying sample input, sample output, and code segments.
Please always include the operating system and shell you're using whenever you start a thread in this forum. Some utilities are not available on all operating systems. Some options on common utilities vary from operating system to operating system. Some shell options (such as arrays) vary from shell to shell. If we don't know what operating system and shell you're using, it is sometimes hard to guess at what the real problem is that you're describing, and hard to create suggestions that will work in your environment.

The command utility takes a "simple" command (a utility and its arguments) as parameters. If does not take a "pipeline", a "compound" command, a "list", an if, a for, or an until loop, or a case statement.

If you want your shell to execute a pipeline (or one of the other non-simple commands listed above) and return the exit status of that pipeline, you need something more like:
Code:
shell -c "pipeline"

where shell is the name of the shell you're using and pipeline is the pipeline you want your shell to run.
Sponsored Links
    #3  
Old 03-12-2018
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 18 July 2018, 4:23 AM EDT
Location: Aachen, Germany
Posts: 13,069
Thanks: 449
Thanked 4,013 Times in 3,690 Posts
Your snippet seems to want to execute every single line in the info file - why not source your file immediately, or just run it (after having chmoded it executable)?
    #4  
Old 05-16-2018
adamlevine adamlevine is offline
Banned
 
Join Date: Mar 2018
Last Activity: 4 June 2018, 5:31 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
oh....
Sponsored Links
    #5  
Old 05-20-2018
adamlevine adamlevine is offline
Banned
 
Join Date: Mar 2018
Last Activity: 4 June 2018, 5:31 AM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks
Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ksh: run commands from pipe Cochise Shell Programming and Scripting 15 10-16-2014 11:41 AM
check for a file and run some commands family_guy UNIX for Dummies Questions & Answers 2 03-18-2009 10:52 AM
Command to run multiple commands from a file. kaixinsjtu UNIX for Dummies Questions & Answers 8 02-16-2009 12:16 AM
Pipe text from a file into an array grahambo2005 Shell Programming and Scripting 8 02-02-2009 11:08 AM
Problem working with Pipe Delimited Text file ravi0435 UNIX for Dummies Questions & Answers 9 01-06-2009 12:04 PM



All times are GMT -4. The time now is 06:57 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?