On a unix/linux system, you can pipe the file through tr
, converting certain characters to others. For example:
cat file.txt | tr ' \n' '#$'
will translate all spaces to #
and all newlines to $
.
If you need to transform CR/LF together, you can use tr ' ' '#'
to change spaces, and pipe output into another tr -t '\r\n' '$'
to change the newlines. The -t
tells tr
to truncate the matched set to the length of the replacement set.
You could also use the utility dos2unix
to first translate all the \r\n
line endings to the more unix \n
, then use the first option.
Example (with \n
only):
$ echo "foo bar" | tr ' \n' '#$' foo#bar$