Whoops, that script won't make much sense, since the carriage returns (ascii or utf 015) got turned into newlines (ascii or utf 012). If you replace each ~ with a carriage return, the script should look like this: tcs -f msdos <$file |[3=1] sam -d /fd/3 <<'!' >[2]/dev/null ,x/~+$/ d ,x/~+/ x/~/ c/\n/ w /fd/1 !