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?

Tags
linux

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 10: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
Executing several commands in a text file ggayathri Emergency UNIX and Linux Support 3 03-15-2016 12:57 AM
Ksh: run commands from pipe Cochise Shell Programming and Scripting 15 10-16-2014 12:41 PM
How to use pipe operator as simple character in text file? ravi.trivedi Shell Programming and Scripting 4 03-02-2013 01:04 PM
how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols vasan2815 Shell Programming and Scripting 4 11-14-2011 07:00 AM
Bash Script Help...search then read from file: change text and pipe back... serverfull Shell Programming and Scripting 1 09-22-2011 11:04 AM
Commands to reorganize a text file gwr Shell Programming and Scripting 11 04-05-2011 11:43 PM
Pipe text from a file into an array grahambo2005 Shell Programming and Scripting 8 02-02-2009 12:08 PM
Replacing a field in pipe delimited TEXT File ravi0435 UNIX for Dummies Questions & Answers 3 01-08-2009 02:54 PM
Problem working with Pipe Delimited Text file ravi0435 UNIX for Dummies Questions & Answers 9 01-06-2009 01:04 PM
Wall, Write, select users, pipe a text file, HELP Before I'm Bald! chimodel UNIX Desktop Questions & Answers 1 03-13-2008 06:50 PM


All times are GMT -4. The time now is 09:59 AM.

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