8

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:)
2
  • printf isn't echo. You need \n.
    – devnull
    Commented Mar 13, 2014 at 17:23
  • printf "(entity:content %s:%s)\n" $ENTITY $CONTENT
    – devnull
    Commented Mar 13, 2014 at 17:23

2 Answers 2

14

You'll just need to add the newline character, \n, to the printf statement:

printf "(entity:content %s:%s)\n" $ENTITY $CONTENT
5

printf doesn't append a newline as standard behaviour, you need to add it to your print string:

printf "(entity:content %s:%s)\n" $ENTITY $CONTENT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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