Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

suppress the output to screen in shell script

Tags:

shell

unix

ksh

awk

Hi i have written a small script:

#!/usr/bin/ksh

for i in *.DAT
do
awk 'BEGIN{OFS=FS=","}$3~/^353/{$3="353861958962"}{print}' $i >> $i_changed
awk '$3~/^353/' $i_changed >> $i_353
rm -rf $i_changed
done

exit

i tested it and its wrking fine. But it is giving the output to screen i dont need the output to screen. i simply need the final file that is made $i_353

how is it possible?

like image 348
Vijay Avatar asked May 11 '11 07:05

Vijay


People also ask

How do I suppress output in R?

By using invisible() function we can suppress the output.

How do I limit bash output?

The -n option tells head to limit the number of lines of output. Alternatively, to limit the output by number of bytes, the -c option would be used.

How do I reduce grep output?

The quiet option ( -q ), causes grep to run silently and not generate any output. Instead, it runs the command and returns an exit status based on success or failure. The return status is 0 for success and nonzero for failure.

How do I run a shell script in silent mode?

To install the Network Shell in silent mode Using any server, create a text file named nsh-install-defaults in the /tmp directory. The file must belong to root. Ensure that the file is in UNIX format (a format in which a line feed, not a carriage return, specifies the end of a line). Otherwise, installation fails.


1 Answers

Wrap the body of the script in braces and redirect to /dev/null:

#!/usr/bin/ksh

{
for i in *.DAT
do
    awk 'BEGIN{OFS=FS=","}$3~/^353/{$3="353861958962"}{print}' $i >> $i_changed
    awk '$3~/^353/' $i_changed >> $i_353
    rm -rf $i_changed
done
} >/dev/null 2>&1

This sends errors to the bit-bucket too. That may not be such a good idea; if you don't want that, remove the 2>&1 redirection.

Also: beware - you probably need to use ${i}_changed and ${i}_353. This is why the output is not going to the files...your variables ${i_changed} and ${i_353} are not initialized, and hence the redirections don't name a file.

like image 168
Jonathan Leffler Avatar answered Sep 28 '22 02:09

Jonathan Leffler