[wellylug] simple super basic bash question
Richard Hector
richard at walnut.gen.nz
Sun Jan 9 00:04:06 NZDT 2005
On Mon, Dec 20, 2004 at 09:53:46PM +1300, Mark Signal wrote:
> if file1 contains "hello" and file2 contains "goodbye" and I 'cat
> file1 file2 > file3' then
> file3 contains 2 lines:
> hello
> goodbye
>
> how do I do this so that file3 contains the contents of file1 and file2
> on one line:
> hello goodbye
I know this was a long time ago, and you got the answer you were after,
but I just spent some time playing around with it.
The hardest task I had was creating file1 and file2 exactly as you
described - the common tools I used insisted on sticking a newline
on the end of each, which is what you presumably had, and which is why
you got 2 lines.
When I did create the files with no newlines, I got this result:
richard at jasper:~/temp$ cat file1
hellorichard at jasper:~/temp$ cat file2
goodbyerichard at jasper:~/temp$ cat file1 file2 > file3
richard at jasper:~/temp$ cat file3
hellogoodbyerichard at jasper:~/temp$
As I say, I know it's not the answer you were looking for; you've
already got that. But I think it is a useful demonstration of what was
actually happening.
BTW - to create the files, I started with the ones you had, then did
dd if=file1 of=file1.tmp bs=1 count=5
mv file1.tmp file1
Another (simpler) way is
echo -n hello > file1
Does anybody know if it's possible to make vi (or vim or whatever) _not_
append a newline?
Thanks,
Richard
More information about the wellylug
mailing list