0

I want to save a few lines as a file etl.xml I tried the following but it is not working for obvious reasons.

cat etl.xml << myscript
<etl>
    <connection id="in" driver="xpath" url="/home/test.xml"/>
        <query connection-id="in">
               /TXNEXP/AUTHADV
         <script connection-id="db">
    </script>
    </query>
 </etl>
myscript
3
  • @Nerian: Shouldn't that be an answer (with a bit of explanation)? Commented Jan 7, 2011 at 11:05
  • @delnan Done :) ask if you need further clarification Commented Jan 7, 2011 at 11:09
  • I would recommend using a here doc marker that stands out visually from the rest of the text. EOF is often used. If you want it to be a little more descriptive, perhaps EOF-myscript. Commented Jan 7, 2011 at 17:43

3 Answers 3

3

Just need one more character:

508 $ cat xmlhere.sh 
#!/bin/bash

cat > etl.xml << myscript
<etl>
    <connection id="in" driver="xpath" url="/home/XXX/WAVtxnexp20101125.xml"/>
        <query connection-id="in">
               /TXNEXP/AUTHADV
         <script connection-id="db">
    </script>
    </query>
 </etl>
myscript

This is a "here document".

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Can you please remove the username after /home/ for security reasons.
@shantanuo It's still visible in edits history (both question & answer)... If your security depends on obfuscation... bad things will happen ;)
1

I assume you want to use some end marker. In that case, the syntax is "cat > outputfile << end_marker":

$ cat > etl.xml << EOF
here I write the file contents
EOF

If, instead, you want to append the line "myscript" to etl.xml, then:

$ echo myscript >> etl.xml

Comments

0

You can do it like this:

cat myscript > etl.xml

or

echo myscript > etl.xml

The flow is:

origin > destiny

Overwrite the contents >

Append >>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.