Using output to input another command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using output to input another command
# 1  
Old 02-14-2008
Tools Using output to input another command

Hi guys. Is it possible (I'm sure it is) to use the output of a simple 'ls' command as input of another command 'tail'.
It is not really the output of the 'ls'. I have to useeach line of the output.

This is the first command...
ls *myFile*021308*

Which it outputs many filenames. For each of those filenames I want to tail them

tail 1.myFlie_021308
tail 2.myFlie_021308

Thanks
Rodrigo
# 2  
Old 02-14-2008
Tools Use a for loop

#! /bin/bash

for zf in *myfile*.*
do
ls -l $zf
tail $zf
done

Notes:
(1) I do an ls command; not needed - just shows what file is being looked at in the loop
(2) tail is its own command line since guess you want to do more than simply execute this one command

This could all be done in one line as:
tail *myfile*.*
but, I figure this is part of something more complicated.
So, two choices.
# 3  
Old 02-14-2008
Quote:
Originally Posted by rodrimuino
Hi guys. Is it possible (I'm sure it is) to use the output of a simple 'ls' command as input of another command 'tail'.
It is not really the output of the 'ls'. I have to useeach line of the output.

This is the first command...
ls *myFile*021308*

Which it outputs many filenames. For each of those filenames I want to tail them

tail 1.myFlie_021308
tail 2.myFlie_021308

Thanks
Rodrigo
Here's another one if you kind of like the output/input style Smilie
Code:
ls | xargs -n1 tail

# 4  
Old 02-14-2008
Thank you both. It was easier than I thought!

Rodrigo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

2. UNIX for Dummies Questions & Answers

Cut command, no input delim, output delim not working

Hello, I'm using cygwin on my Windows 7 machine. From the man pages of cut: --output-delimiter=STRING use STRING as the output delimiter the default is to use the input delimiter I tried the following commands and got the error messages: $ cut -c1-10,20-30 -d... (10 Replies)
Discussion started by: kojac
10 Replies

3. Shell Programming and Scripting

Script output as input for next command

Hi All, Hoping you can help as im in desperate need... I'm very new to unix scripting so apoligies, I have setup an expect script in order to log into a node on our network, This will provide an output as per the below *********** information: *************: n/a TEST IP : n/a ... (18 Replies)
Discussion started by: mutley2202
18 Replies

4. UNIX for Dummies Questions & Answers

Using grep output as input for sed command

Hi, I would like to know if this is possible, and if so what can i do to make this work. I would like to grep a line X from fileA and then use the output to replace a word Y in fileB. grep "line X" fileA | sed -e 's/Y/X/g' > outfile this statement does not work, as i do not know how to... (7 Replies)
Discussion started by: cavanac2
7 Replies

5. Shell Programming and Scripting

Command Output to Standard Input

Hi All, How do I provide the output of a command to another command which is waiting for an input from the user ? Ex : I need to login to a device via telnet. In the script, initially I use the "read" command to get the IP Address, Username and Password of the device from the user. Now,... (1 Reply)
Discussion started by: sushant172
1 Replies

6. UNIX for Dummies Questions & Answers

Send output of grep as input of kill command

I would appreciate any help. I need to run 'ps -ef | grep 'process', get the process id and kill that process. I have got this far: - Get pid using ps -ef | awk '/process/{ print $2}' after this I'm kind of stuck.. - Use pipe to redirect the output to kill pid=ps -ef | awk '/bmserver/{... (2 Replies)
Discussion started by: foxtron
2 Replies

7. Shell Programming and Scripting

how to input the CAT command output in Shell

Hi guys... I am new to this scripting...so please forgive me if anything worng in my questions... here is my question.. I have file structure /home/oracle/<sid>/logs/bkup now i want to write a script which should grep the sid name from a file..and it should replace the <SID> with... (1 Reply)
Discussion started by: troubleurheart
1 Replies

8. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

9. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

10. Shell Programming and Scripting

Using Output from one command as input to another

This site has been very helpful thus far.. I thank you all in advance for sharing the knowledge. Let me get to it. I am trying to write a very small script to take away from the boredom of doing the same thing over and over. Everynow and again I have to get the hex value of a file using a... (2 Replies)
Discussion started by: BkontheShell718
2 Replies
Login or Register to Ask a Question