Escape sequences in BRO (\n)

Hi. I got a trouble with escape sequences in Bro.
When i write:
print “Next words must be in a new line \n New line”
or
print “\n”

\n will decoded in x0a or \n, but not decoded as a new.

So there is a question: how can i make a new line in strings? F.e. i read several strings of data and need to from string like
“hi,
its a new line
and it is too!”

but only thing i have is “hi,\nits a new line\nand it is too!”

Thanks for answer

Have you tried using the fmt function in conjunction with the print function?
https://www.bro.org/sphinx/scripts/base/bif/bro.bif.bro.html#id-fmt

-AK

Yeah. The code:
local line = fmt("%s", “Hi \n all!”);
print line;

will print the Hi \n all!
:frowning:

sorry, it will print Hi \x0a all!

And if slash is double: fmt("%s", “Hi \n all!”);

it will print Hi \n all!

Shouldn't the \n be in the format specifier? Eg.,

   local lines = fmt("%s\n%s\n", "First line", "Second line");

I don't think C or perl or other shell scripts with printf-like
capabilities would behave differently: the controls have to be in the
format specifier, not the data.

- Pat

Well, the printed line for this sample is:

First line\x0aSecond line\x0a

Bro escapes strings that are printed by default. You need to open a file(or stdout) in raw mode in order for it to output strings as-is

global myfile = open("-");
enable_raw_output(myfile);
print myfile, "hello\nworld";
close(myfile);

or

global myfile = open("-") &raw_output;
print myfile, "hello\nworld";
close(my file);

My thanks! It works.