0

I have a script that I want to run and then write the output to a file in a specific format
Currently when I run the script and direct it to standard output it gives it to me in the format I want. The issue is when I try to send it to a file it loses the formatting and just gives me the output in the file on the same line
Here is the output that I want written in this specific way to the file:
Wanted output
and here is what it actually gives me when I write it to a file
Actual output
Here is my code for this

printf "%s\n" "==================" >> test
printf "%s\n" "Disk Space. Look for /" >> test
printf "%s\n" "==================" >> test
printf "%s\n" $(df | grep '/dev/') >> test 
printf "%s\n" "==================" >> test


How I can the output in the file to look like the output in the command line.

Edit: I am running this through plink (putty command line) and these commands are in my command file that I am using.

  • Your code is fine for apps that run on Linux, but it looks like you want the file to be used on Windows (your screenshot shows Notepad). Is that correct? – Mark Plotnick Mar 22 at 17:17
  • sorry, I should have added I am running this through plink (putty command line) from a linux box and the commands are just the command file I am using to pass the commands to the linux box – hescobar Mar 22 at 17:20
  • 1
  • 2
    If you want to use your files on Windows, replace \n with \r\n, as that is the default end-of-line marker there. Or simply use literally any other editor than notepad, as that seems to be the only program that still has trouble with this. Notepad++ seems to be a favorite among many, though wordpad.exe also works and comes preinstalled with Windows. – Entropy0 Mar 22 at 17:31
1

From your screenshot, it seems you're viewing the file in Windows's Notepad. It only recognizes Windows-style line-endings (CR+LF), and shows files with Unix-style line-endings just like that, on a single line.

You can change \n to \r\n in your printf to output Windows-style line-endings instead.

  • 1
    Actually this answered my question perfectly. Maybe a bit more detail would have been nice but it really does though. Thank you – hescobar Mar 22 at 19:17
0

You can probably run your file through unix2dos (the opposite of dos2unix, but pulling from the same dos2unix-* rpm), then sending your file to your destination. This should get your file to play nice in Windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.