[aklug] Fwd: Re: Re: noob scripting question -- file input/output

From: <jim@macdonald.org>
Date: Fri Oct 31 2008 - 16:39:32 AKDT

 For some reason my email client puked on the send
What I was say= ing was that typically you can just pipe the output of one
command into ano= ther. Lets say you want to capture the stdout and stderr
toa file:
$> df -h 2>&1 >output.out

Now lets say you wan= t to output the results of "df -h" to grep so you can
just see the inf= ormation for /etc

$> df -h 2>&1 |grep etc

N= ow lets say you want to just grab the free space of /etc/ from df -h
$> df -h |grep etc| cut -d' ' -f3

note the fieldnumber = (f3) might be wrong, I am writing this on a windows
machine and can't check= the output but you get the point.

either way you do it there sh= ould not be a reason you have to cat the
resulting text file of a command t= o get it to input to another command.
you should be able to just run = the command and redirect the stdout through
a pipe to the next command.
the only real useful thing I have found for cat is to pipe the con= tents of
two files together. Thusly:

cat file1 file2 >file3
else use grep because chances are you are looking for a particul= ar entry
ina file anyway.

Hope this helps.

PS. one= other thing that you can do with the 2>&1 syntax is output the
stdo=ut and stderr to a text file AND output it to the tty so you can see
theer= rors in real time and the go back and grep for the particulars later
=
$>df -h 2>&1 |tee error.out

Jim

On Oct 31, 2008, royce@alaska.net wrote: Good stuff - intended to rep= ly
all?

Jim MacDonald wrote:
>I was doing something jus= t like this last night... typically if you are
>running a command = say DF-k for example.

---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Fri Oct 31 16:39:49 2008

This archive was generated by hypermail 2.1.8 : Fri Oct 31 2008 - 16:39:49 AKDT