👤
Home Man
Search
Today's Posts
Register

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
# 1  
Old 03-11-2018
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.
# 2  
Old 03-11-2018
Quote:
Originally Posted by adamlevine
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.
# 3  
Old 03-12-2018
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
oh....
# 5  
Old 05-20-2018
Thanks
👤 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
Perl telnet to router run commands from file numele Shell Programming and Scripting 1 11-12-2013 09:18 PM
How to use pipe operator as simple character in text file? ravi.trivedi Shell Programming and Scripting 4 03-02-2013 12:04 PM
Help with shell script to run the commands reading options from local file itsprout Shell Programming and Scripting 2 06-29-2009 12:26 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
Replacing a field in pipe delimited TEXT File ravi0435 UNIX for Dummies Questions & Answers 3 01-08-2009 01:54 PM
Problem working with Pipe Delimited Text file ravi0435 UNIX for Dummies Questions & Answers 9 01-06-2009 12:04 PM
Wall, Write, select users, pipe a text file, HELP Before I'm Bald! chimodel UNIX Desktop Questions & Answers 1 03-13-2008 05:50 PM


All times are GMT -4. The time now is 11:13 PM.

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