pipe output to script as command line argument


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers pipe output to script as command line argument
# 1  
Old 04-26-2008
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:

Code:
 
find . -xdev -type f -size +4096 -exec ls -al {} \;

i wan to be able to do something like:

Code:
echo +4096 | find . -xdev -type f -size ****** -exec ls -al {} \;

Is this possible in ksh?
# 2  
Old 04-26-2008
Code:
find . -xdev -type f -size `echo +4096` -exec ls -al {} \;

Depending on where the +4096 is meant to come from, you might be looking for something as simple as

Code:
#!/bin/sh

case $# in 1);; *) echo "Syntax: $0 size -- find files of size <size>" >&2; exit 1;; esac

find . -xdev -type f -size "$1" -exec ls -al {} \;

Another construct which is useful sometimes is

Code:
sed -e 's/.*/find . -xdev -type f -size & -exec ls -al {} \;/' fileofsizeswewanttofind |
sh

And finally, you might want to look at xargs, which allows for rather similar constructions; but it's tricky for this particular case.
# 3  
Old 04-26-2008
actually i was not looking to write a script.

i wanted a simple way to do this via the command line. and my find was jut an example. i wanted something that would work for any script/command i am running.

make sense or did i just confuse people?
# 4  
Old 04-26-2008
And the backticks don't fit that definition?

Anything you can do in a script, you can do on the command line, anyway.

For the general solution, xargs is probably closest to what you have in mind, but it doesn't interact nicely with find -exec, because they both want the {} for themselves. (Actually, you can in fact specify an alternate placeholder for xargs.)

Code:
echo fnord | xargs ls -l

would be the xargs way of saying "ls -l fnord", and

Code:
echo +4096 | xargs -i find . -xdev -type f -size {} -ls

would be something similar for find, albeit without the -exec.
This User Gave Thanks to era For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pipe command output to shell script?

Hi Team, Need a help on how to pipe a command out put to a shell script. My shell script looks like below. cat shell_script #!/usr/bin/ksh input =$@ echo " we are inside the shell script" echo " here are the input parameters" .......................... .................. ... (11 Replies)
Discussion started by: gvkumar25
11 Replies

2. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. UNIX for Dummies Questions & Answers

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script (8 Replies)
Discussion started by: Nsharma3006
8 Replies

4. Shell Programming and Scripting

How to pass command line argument in shell script?

I need to write a shell script, when I run that script I should pass those arguments if not, then script should not run and pass the error message like invalid option - - should pass the argument. and Exit from the script https://www.unix.com/images/misc/progress.gif (1 Reply)
Discussion started by: Nsharma3006
1 Replies

5. 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

6. Shell Programming and Scripting

Passing value as a command line argument in awk script.

I have one working awk command line. Which taking data from the “J1202523.TXT” file and generating the “brazil.dat” file. PFB code. awk '{ DUNS = substr($0,0,9);if ( substr($0,14,3) == "089" ) print DUNS }' J1202523.TXT > Brazil.dat But now I want to pass two parameter as a command line argument... (4 Replies)
Discussion started by: humaemo
4 Replies

7. 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

8. Shell Programming and Scripting

shell script for ftp files passed in command line argument

i want to write a shell script function that will ftp the files passed in the command line . i have written a shell script for ftp but how will it do for all files passed in command line argument , i am passing 4 files as argument ./ftp.sh file1 file2 file3 file4 code written by me... (5 Replies)
Discussion started by: rateeshkumar
5 Replies

9. UNIX for Dummies Questions & Answers

Passing command output as an argument to a shell script

Hi, I have a very small requirement where i need to pass command output as an argument while invoking the shell script.. I need to call like this sh testscript.sh ' ls -t Appl*and*abc* | head -n 1' This will list one file name as ana argument.. I will be using "$1" in the shell... (2 Replies)
Discussion started by: pssandeep
2 Replies

10. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies
Login or Register to Ask a Question