0

I have a log file that contains output from

/bin/df -h| /usr/bin/grep p_log|/usr/bin/awk -v date="$(date)" '{print date,$4,$5}'

which is later sent out using mailx. It arrives in my PC's Outlook as desired with a line per entry and displays with a line end in cat -A:

Wed Mar 16 10:29:01 EDT 2022 291G 95%$
Wed Mar 16 11:29:01 EDT 2022 290G 95%$
Wed Mar 16 12:29:02 EDT 2022 290G 95%$

Adding an additional field to the awk - $6 happens to be the last field in the df output - still displays the same with cat:

Wed Mar 16 11:29:01 EDT 2022 290G 95%$
Wed Mar 16 12:29:02 EDT 2022 290G 95%$
Wed Mar 16 13:29:01 EDT 2022 290G 95% /.p_log$
Wed Mar 16 14:29:02 EDT 2022 290G 95% /.p_log$

But lines are now concatenated when read in Windows/Outlook:

Wed Mar 16 10:29:01 EDT 2022 291G 95%
Wed Mar 16 11:29:01 EDT 2022 290G 95%
Wed Mar 16 12:29:02 EDT 2022 290G 95%
Wed Mar 16 13:29:01 EDT 2022 290G 95% /.p_log Wed Mar 16 14:29:02 EDT 2022 290G 95% /.p_log 

I found another post at explains that cat -e (which I have tried, and is encompassed by -A) "displays Unix line endings (\n or LF) as $ and Windows line endings (\r\n or CRLF) as ^M$". Why then are two lines that display the same control characters in cat being displayed differently in Windows/how best to get the line feed back when printing $6 without messing up the formatting of the log? I presume there are more hidden control characters that cat -A does not display, i.e. that 'all' does not actually mean all.

Further testing: There are header and footer lines - all ending in the same "$"- that do not get concatenated. I tried attaching the content from the end of one of the concatenated lines to a header line and that would indicate that it's the "/" that's causing the problem, but only for mailx.

Looks like I've been barking up the wrong tree; not sure if I should delete this question and open a new one for mailx?

imac
  • 47
  • 9
  • On what OS are you running this: `/bin/df -h| /usr/bin/grep p_log|/usr/bin/awk` ? Windows / WSL / linux ? – Luuk Mar 18 '22 at 13:28
  • If it comes from WSL or Linux, try: `unix2dos`, see: [Convert Unix line endings to Windows](https://superuser.com/questions/71507/convert-unix-line-endings-to-windows). Or if it's coming from a mac, you can use `mac2unix | unix2dos` – Luuk Mar 18 '22 at 13:29
  • Df is run on SUSE linux box. I know there are utilities to convert on type to another, but what confuses me is that what looks like the same $ ending is being treated differently – imac Mar 18 '22 at 14:35
  • see: [Historical reason behind different line ending at different platforms](https://stackoverflow.com/questions/419291/historical-reason-behind-different-line-ending-at-different-platforms) – Luuk Mar 18 '22 at 14:51

1 Answers1

0

Adding two spaces to the start of each line - https://stackoverflow.com/a/22098987/8823709 - resolved the issue. I don't know why, but it did.

imac
  • 47
  • 9