I have a cron job which runs a long script producing lots of output. Some of the output is lines delimited by single carriage returns; when run from the command line, these make the successive lines overwrite each other, providing progress output without overly polluting the backscroll. However, when looking at the output from the cron job, I want to see all these lines without missing any.

Until recently, when I used mailx to print the output reports from the cronjob, it would replace the control characters with reverse-video ^M to highlight them. This was the behavior I wanted, as it left all of the lines visible. Now, however, something unknown has changed (a version upgrade?), and mailx prints the control characters as-is, causing them to overwrite each other when mail is printed. How can I reverse this behavior and make mailx replace control characters again?

  • Is this for the display of mail being read by mailx from a user's mail spool file?
    – thrig
    Jan 15, 2016 at 18:59
  • Yes. The data are raw in the mail spool file; viewing them through mailx now prints the control characters directly, rather than escaping/replacing them as I'd prefer.
    – Tom Hunt
    Jan 15, 2016 at 19:02

2 Answers 2


You could pipe the output through tr before processing it further or sending it.

./your-script | tr "\r" "\n" | mail

This should replace all carriage return characters with line feeds.

The same would be possible within the crontab:

* * * * 2 /path/to/your-script --args | tr "\r" "\n"
  • I run the script from cron. cron grabs all the stdout entirely on its own and mails it to me. I do not have control over this process. I could change the invocation and rewrite the script, but I did not need to do this a week ago and I don't much want to do it now.
    – Tom Hunt
    Jan 15, 2016 at 20:59
  • 1
    You could add the tr to the respective cronjob: * * * * * ./your-script --with many params | tr "\r" "\n". Should save you from rewriting the script.
    – tarleb
    Jan 15, 2016 at 21:12

It turned out that the issue lay with mailx's pager setting. It began using more for some reason, when previously it had used less (which does the escaping). Linking more to less again restored the old behavior.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .