Screen output suppression in shell script

Hi, I wrote 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 toss it. But it gives output to the screen, I do not need output to the screen. I just need the final file made by $i_353

how is this possible?

+4
source share
1 answer

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 

It also sends errors to the bit bucket. Perhaps this is not such a good idea; if you do not want this, remove the redirection 2>&1 .

Also: beware - you probably need to use ${i}_changed and ${i}_353 . That's why the output does not go to files ... your variables ${i_changed} and ${i_353} not initialized, and therefore redirects do not name the file.

+6
source

All Articles