I am trying to create a text file foobar.txt using \immediate\write18, and can not figure out how to properly get the \n so that Unix puts these lines on a new line. The MWE below produces one line in the output file:
\n \n ---------\n Foo: foo \n Foo: foo \n Bar: bar \n
What I want in the output file is a few blank lines followed by:
---------
Foo: foo
Bar: bar
Additional Question:
- This appears to always append to the file, where as I thought the normal Unix way is that single
>overwrites the file, and the double>>appends to the file. How can I get it to overwrite the file if it already exists. Or is this a security feature that prohibits this.
Notes:
- The values after the colon are not fixed, but are built during compile time. Otherwise a simple
catsolution would have worked.
Code:
\documentclass{article}
\begin{document}
\immediate\write18{%
echo " \string\n" > foobar.txt%
echo " \string\n" >> foobar.txt%
echo "---------\string\n" >> foobar.txt%
echo "Foo: foo \string\n" >> foobar.txt%
echo "Foo: foo \string\n" >> foobar.txt%
echo "Bar: bar \string\n" >> foobar.txt%
}
\end{document}
filecontentspackage? – Werner Jul 12 '12 at 22:58\writemechanism? – egreg Jul 12 '12 at 23:03echo's default behaviour is to disable the interpretation of backslash escapes, soecho "a\nb\nc"will print the line as it is. If you want to enable the escapes, add the-eflag toecho.:)– Paulo Cereda Jul 13 '12 at 00:59filecontentspackage, but usingechowas simpler. – Peter Grill Jul 18 '12 at 01:35