For example:
cat a.txt
1 2
1 6
{ cat $HOME/SANITY/file.txt | grep 1 >> $HOME/SANITY/new.txt } > /dev/null
cut -d' ' -f2
Now i don't want the results to be shown when running the script with this code.
You can redirect the output. if you only use your_command > /dev/null only stdout will be redirected. If you want to remove the output of stderr as well, redirect stderr to stdout and stdout to /dev/null using:
your_command > /dev/null 2>&1
2>&1 will move stderr to the file descriptor of stdout.
command is the name of an actual built-in command that's part of the shell -- not necessarily ideal as a placeholder name.Simply use in your case :
grep 1 "$HOME/SANITY/file.txt" >> "$HOME/SANITY/new.txt"
And for general purpose :
command_foo_bar > /dev/null # or any other non special file
grep -q 1./dev/nullto get rid of it.awkinstead of thisgrep/cutcombination.catgoes togrep, and the output ofgrepgoes tonew.txt. What results are you seeing go to the terminal instead?> /dev/null), so it's not clear what the problem is.