why on executing following script each printf (tried also with echo) is printed on the same line??
function read_dom () {
local IFS=\>
read -d \< ENTITY CONTENT
}
cat my_xml_file.xml | \
{ while read_dom; do
printf "(entity:content %s:%s)" $ENTITY $CONTENT
}
Now, this produces a single line output:
(entity:content member:)(entity:content name:id)(entity:content /name:)
How do I change this to multiline, like:
(entity:content member:)
(entity:content name:id)
(entity:content /name:)
Using the backslash character for newline “ ” is the conventional way. However, it’s also possible to denote newlines using the “$” sign. The echo command takes a string as input and prints it out on the console screen. To print any text, we use the echo command in the following manner: As mentioned earlier, the newline character is “ ”, right?
On the default bash implementation, that means (from help echo ): Make it into something that isn't an option by including another character. For example, tell echo not to print a newline with -n, then tell it to interpret backslash escapes with -e and add the newline explicitly.
For example, tell echo not to print a newline with -n, then tell it to interpret backslash escapes with -e and add the newline explicitly. That, however, adds a space which you probably don't want. Use a non-printing character before it. Here.
The most common way is to use the echo command. However, the printf command also works fine. Using the backslash character for newline “ ” is the conventional way. However, it’s also possible to denote newlines using the “$” sign. The echo command takes a string as input and prints it out on the console screen.
You'll just need to add the newline character, \n
, to the printf
statement:
printf "(entity:content %s:%s)\n" $ENTITY $CONTENT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With