Replace a control character with another control character

sedspecial characterstext processing

A csv file is being generated with a form feed (\f) character. This makes it hard to read in excel, etc.

How can I convert the form feed character into a newline (\n) character?

All my searches so far show how to replace control character with a literal character, not with another special character

Best Answer

With GNU sed:

sed 's/\f/\n/g' file

Other seds:

sed "$(printf 's/\f/\\\n/g')" file

Or with tr:

tr '\f' '\n' <file

With perl:

perl -pi -e 's/\f/\n/g' file

The -i is to overwrite the file in-place. For in-place editing with tr:

tr '\f' '\n' < file 1<> file
Related Question