Pipe data to shell script


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 03-14-2007
Pipe data to shell script

Sorry about the noobish question but...

How do I capture data thats piped to my script?

For instance,
Code:
ls -al | myscript.sh

How do I access the output from ls -al in myscript.sh?
# 2  
Old 03-14-2007
Quote:
Originally Posted by tomjones07
Sorry about the noobish question but...

How do I capture data thats piped to my script?

For instance,
Code:
ls -al | myscript.sh

How do I access the output from ls -al in myscript.sh?
A basic simple way

Code:
#!/usr/bin/ksh
cat - | while read LINE
do
  echo aa${LINE}bb
done

# 3  
Old 03-14-2007
The first command in your script will accept the input from the pipe. So if you just want to capture it to a file, then try...
Code:
cat > file1

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How to send data to previous program (pipe)? JackK Shell Programming and Scripting 24 03-26-2018 07:59 PM
Processing files one by one using data from pipe useretail UNIX for Beginners Questions & Answers 3 11-12-2017 09:10 AM
Shuffle Columns in Pipe delimited data BrahmaNaiduA Shell Programming and Scripting 10 02-24-2015 12:56 PM
How to pipe command output to shell script? gvkumar25 Shell Programming and Scripting 11 02-18-2015 12:02 AM
Shell script to read lines in a text file and filter user data Shell Programming and Scripting VikrantD UNIX for Dummies Questions & Answers 3 03-25-2014 03:28 AM
Read pipe data shubh05 Shell Programming and Scripting 7 12-11-2012 01:19 PM
Convert column data to row data using shell script sktkpl UNIX for Advanced & Expert Users 4 06-06-2012 05:55 AM
Data pipe lost when using ssh in shell script siavash Shell Programming and Scripting 2 02-01-2012 06:28 AM
Using Named pipe in shell script sudvishw Shell Programming and Scripting 2 09-12-2011 05:21 AM
AIX 5.3 - There is no process to read data written to a pipe vigsgb UNIX for Advanced & Expert Users 6 05-22-2009 04:59 AM
Need help with shell script for chekking a column in txt file - pipe delimited ravi0435 UNIX for Dummies Questions & Answers 12 01-02-2009 03:31 PM
Extracting Data from Pipe Delimied file Meem UNIX for Dummies Questions & Answers 2 10-17-2008 12:28 AM
Reading from blocking fifo pipe in shell script victorin Shell Programming and Scripting 4 05-08-2007 11:39 AM
Pipe Data From Grep Into A File katinicsdad Shell Programming and Scripting 4 09-08-2006 11:20 AM
Need help capturing pipe to a file in shell script heinz Shell Programming and Scripting 6 11-03-2005 07:27 AM