koala_man 1414084254 learn sponge() { data=$(cat; printf x); printf "%s" "${data%x}" > "$1"; }; # read and write the same file in a pipeline: grep -v '^#' file | sponge file koala_man 1414084558 forget koala_man 1414084570 learn sponge() ( tmp=$(mktemp) && cat > "$tmp" && cat -- "$tmp" > "$1" && rm -- "$tmp"; ) # read and write the same file in a pipeline: grep -v '^#' file | sponge file