Adding a new line to a script

Good Morning,

I have a log file on a solaris 9 machine that gets appended this way:

printf "\nBlahBlahBlah - $TIME"

but it doesn't create a new line. I have to go into the file and split the bottom line up manually. Any ideas why

\n

isn't doing what I want?

You mean there's no \n before BlahBlahBlah or after $TIME at the end of the file? It's usual to put the \n after what you want to print, not before it (e.g. printf "BlahBlahBlah - $TIME\n" ). As it is, anything added to the end of the file (not added by your printf with its leading \n) will go directly after $TIME, on the same line.

1 Like

Do you actually run

printf ... >> logfile

?

1 Like

OK I made that change, we'll see what happens.

Thanks everyone.. Found the problem. This issue was Notepad's treatment of

\n

. Apparently, you have to add a carriage return for a lot of applications, so -

\r\n blahblahblah

will put the text on a new line.

No. This is true ONLY for MS environments. Any *nix style system uses \n exclusively; in fact, the presence of \r in data files or scripts is the cause for many errors.
Another reason to insist on people showing their system / environment...

1 Like

Sweet..it worked well over the weekend on all the scripts except one. That script used

echo

to write to the file instead of

printf

so I changed that one for next time. Apparently

echo

has fewer formatting options.