How to pipe command output to shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pipe command output to shell script?
# 8  
Old 12-14-2014
Can I suggest redirect of stderr to stdout like this:

Code:
 ls x 2>&1 | output_log

This User Gave Thanks to Chubler_XL For This Post:
# 9  
Old 02-08-2015
Basically what I am looking is to format command out put. I tried in below way also
ls -lrt 2>&1 | output_log
[INFO][Feb 08 16:11:10] total 112


I can see only first line in the output. Rest of the lines are missing.
# 10  
Old 02-08-2015
Is it about this?
Code:
#!/usr/bin/env bash
# File: 	pipe
#
#	Variables
#
	C=0
#
#	Action & Display
#
	# Prepare arg list
	if [ $# -eq 0 ]
	then	[ -t 0 ] && printf "Input: "
		read input
	else	input=$@
	fi
	
	#Parse args
	for a in $input
	do
		echo "$C -- some text preparations $a"
		C=$(( $C + 1 ))
	done

Command / Output:
Code:
echo x y z | pipe
0 -- some text preparations x
1 -- some text preparations y
2 -- some text preparations z

As you see i've reused the template from ChubblerXL.

hth
# 11  
Old 02-18-2015
Hi Sea,

Thanks for your reply. What I am looking is to format the out put. I want to format even when we have an error. It is working fine when we have o/p but it is failing when we have an error or output contains more than single line.
# 12  
Old 02-18-2015
You cannot 'format' an error message.
But you can form an error message, as in catching values that would cause an error, and then format a message and print it to the user.
However, that is another step.

Could you provide some sample input, desired output and what you have tried so far?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the output of w command in pipe delimited format

Since output of w command have variable number of columns I want to get the output in pipe delimited format. I tried export OFS="|"; w but that does not work. Any ideas? (4 Replies)
Discussion started by: Soham
4 Replies

2. SuSE

Find command doesn't pipe the output as required.

Hi, I am using below code snippet to echo/display the files found (matching a pattern from searchstring.out file) and the corresponding owner. while read j do echo "Pattern to search is:- $j" find / -name "*$j*" |\ while read k do echo "File found is:- $k" owner=$(ls... (9 Replies)
Discussion started by: Vipin Batra
9 Replies

3. Shell Programming and Scripting

Pipe output a command to another using xargs

xargs work great when a command gives multiple line output which can be input to another. In my case it is not working coz the second command uses two words in it. $ scr.sh gives output like 193740 638102 375449 .. .. another command takes these number as inputs. it works great... (1 Reply)
Discussion started by: mahesh113
1 Replies

4. UNIX for Dummies Questions & Answers

is there any way of using rm command on output of pipe

Hi, I am having a list of directories with different login id's. My requirement is that i need to list the directories of my id and need to delete them. So i am using following code ls -ltr ¦ grep userid ¦ rm -rf But this is not working. So is there any way of doing it. Please note... (3 Replies)
Discussion started by: sarbjit
3 Replies

5. Shell Programming and Scripting

shell script to format command output

Hello team, I am running below command which is giving following output. bash-3.00$ ps -eo pid,pcpu,args | sort +1n | grep -i java 12 0.0 grep -i java 8804 0.0 /opt/app/ccr/home/ccr/WebSphere/AppServer/java/bin/sparcv9/java -XX:+UnlockDiag 9241 0.0... (7 Replies)
Discussion started by: coolguyamy
7 Replies

6. Shell Programming and Scripting

Assign command (with pipe) output to a variable

Hi , I would like to assign command (with pipe) output to a variable. The code is as follows. The goal of the code is to get the last folder folder with a particular name pattern. myDate=`ls | grep 2009 | tail -1` echo "myDate=" $myDate However, in the presence of the pipe, the code... (3 Replies)
Discussion started by: jeff_cen
3 Replies

7. UNIX for Dummies Questions & Answers

pipe output to script as command line argument

i want to redirect output of one command as the command line argument of another script for example, say i would run this command: find . -xdev -type f -size +4096 -exec ls -al {} \; i wan to be able to do something like: echo +4096 | find . -xdev -type f -size ****** -exec... (3 Replies)
Discussion started by: IMTheNachoMan
3 Replies

8. Shell Programming and Scripting

reading command output from shell script

Hi List, How to read the output of a command executed from a script. For ex. sample_scritp.sh ------------- useradd testuser1 password testuser1 .... ..... -------------- This prompts for "password", and "confirm password", for which i need to give the values from script. Can... (4 Replies)
Discussion started by: sri b
4 Replies

9. Shell Programming and Scripting

Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD cd public_html/crap dir $FILE quit END_SCRIPT Where the $ variable... (2 Replies)
Discussion started by: designflaw
2 Replies
Login or Register to Ask a Question