Shell cat problem

sometext :-
Code:
hello\
\
world\
cat sometext >txt1

cat <<EOF >txt2
hello\
\
world\
EOF


I expected txt1 txt2 to be the same, but they are not. txt2 loses linefeeds. Is this to be expected and how do I get around this?
 
This is expected behavior. The backslash in a HEREDOC means it should continue on the same line. Similar to what you do with code:
Code:
#!/bin/sh

cat something | \
 grep sameline
That's the same as:
Code:
#!/bin/sh

cat something | grep sameline
 
Can I escape it in some way?
Maybe you try crochet work. That might be within the reach of your capabilities.

Escaping to other low profile forums might give us some relief of your high frequency posting.

YEAH! Another "cheap shot" from me. The FreeBSD-forums have been taken over by balanga and wait for being renamed to BALANGA-Forums.
 
I actually need a backslash... sed requires it to create newlines. Can I escape it in some way?

From the sh man page: "If the delimiter as specified on the initial line is quoted, then the here-doc-text is treated literally,"
Code:
$ cat <<"EOF" >test
> hello\
> \
> world\
> EOF
$ cat -e test
hello\$
\$
world\$
Or escape the backslash as usual:
Code:
$ cat <<EOF >test
> hello\\
> \\
> world\\
> EOF
$ cat -e test
hello\$
\$
world\$
 
Back
Top