Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
A GNU/Linux package, moreutils, contains a few interesting utilities. Of relevance here is sponge. It sucks up data from STDIN, and spits it out to a file of your choice [default STDOUT] at EOF. This alleviates the common error of re-directing STDOUT to the original input file. It's a good general solution, but it does involve using a temporary file -- we often accept a little overhead for convenience.
Here's a demonstration driver script using cat and sed:
Producing:
Not everyone wants to obtain GNU/Linux utilities, so I hacked together a perl script to do the basic job. No warranties, etc.:
So sponge can be used for any such situation, sed, awk, grep, etc. To make effective use of sponge, you'd probably want to place it in a directory in your path, say, $HOME/bin for most users. That would eliminate the requirement of needing it in the current directory.
Kernighan and Pike addressed this issue in a slightly different way in 1978 with a script called overwrite in The UNIX Programming Environment, page 152 ff.
One possible useful modification would be to omit the temporary file if the data i short enough -- left as an exercise for the reader ... cheers, drl
Bit of a strange one.
Have a script called rapidclone_test.sh which calls Oracle rapidclone using su -c as an oracle osuser. However, if I control+c out to the calling shell anything entered is not displayed on the terminal. Any command executes successfully though.
Why is the standard... (1 Reply)
I ran the following command.
cat abc.c > abc.c
I got message the following message from command cat:
cat: abc.c : input file is same as the output file
How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Hi,
I am unable to get this script to work as desired. Basically, if an argument "log" is sent into the script, it outputs the result of the Make to a file output.log. However, if the argument is not passed, I want the output to be just put on screen (no redirection). See code snippet below.
#... (3 Replies)
Hi all .... vexing problem here ...
I am using sed to replace some special characters in a .txt file:
sed -e 's/_<ED>_/_355_/g;s/_<F3>_/_363_/g;s/_<E1>_/_341_/g' filename.txt
This command replaces <ED> with í , <F3> with ó and <E1> with á.
When I run the command to standard output, it works... (1 Reply)
Hi guys,
i have a script named purgeErrors.ksh, when i execute this script i need to redirect the output to a log file in the same directory, how can i do that ??
-- Aditya (5 Replies)
Hey, I'm completely new at this and I was wondering if there is a way that I would be able to redirect the log files in a directories standard output and standard error into and excel spreadsheet in anyway?
Please remember don't use too advanced of terminology as I just started using shell... (6 Replies)
Hi,
In Perl, how can we define a variable make it read the value from the standard input? Meaning, how can have the user type in the value that will be assigned to the variable?
Thanks, (2 Replies)
hi folks
how do i output contents of file in standard output.
in my script, i say
x=`cat filename'
echo $x
below is the actual file
***********
asda afdf fdf sdf dsfsdfsd fds dsfdfsdfsdg ssgd sgdg
sdfsdgfsdg dgfd gsfd gs sdg sfdg s
in my script, i am trying to output the... (4 Replies)
Hey guys, need some help. Running AIX Version 5.2 and one of our cron jobs is writing errors to a log file. Any ideas on the following error message.
Error: Internal system error: Unable to initialize standard output file
I'm guessing more info might be needed, so let me know.
Thanks (2 Replies)
When I run a third parties program from the command line (this program basically list's a whole load of stuff) and write the output to a file it splits the output, i.e. in the middle of the file appears the exit command.
If I don't redirect the output and write it to tty then the output is... (3 Replies)