bash programming question

Suppose you have file1 containing the character "1" and file2 containing "2"
Then obviously
[root@gateway root]# cat file1
1
[root@gateway root]# cat file1 file2
1
2
Now if I write the contents of file1 and file2 to file3
I can try any combination of bash commands available and it is alway only possible to obtain a file3 with the contents of file1 and file2 written on separate lines in file3 i.e
[root@gateway root] cat file3
1
2
THE QUESTION IS. Is there away to write the contents of file1 and file2  to file3 such that
[root@gateway root]# cat file3
1 2

Although extremely simple in concept I could not find the proper commands/combinations to effect this.
LVL 1
dryzoneAsked:
Who is Participating?
 
ahoffmannConnect With a Mentor Commented:
(cat file1|tr '\012' ' '; cat file2) > file3
# note that this replaces all newlines, but you gave a file with only one line ;-)
0
 
lewis_looCommented:
how about this:

cat file1+file2 > file3
0
 
lewis_looCommented:
I do a mistake so this is the answer

cat file1 file2 > file3

how about this?
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
dryzoneAuthor Commented:
Thanks for the prompt response lewis.
Nope, the problem still persists.

Take the following clear example.

Create file1 and 2 containing some single line strings and test them with cat.
[root@gateway root]# echo "BlaBlaBla" >file2
[root@gateway root]# cat file2
BlaBlaBla

[root@gateway root]# echo "BooBooBoo" >file1
[root@gateway root]# cat file1
BooBooBoo

Now I try your solution namely;

[root@gateway root]# cat file1 file2 >file3
[root@gateway root]# cat file3
BooBooBoo
BlaBlaBla
[root@gateway root]#

Which is not what I want! I want;
BooBooBooBlaBlaBla

Youre close, keep trying - I just have to get this faxspooler working. This must be easy.
0
 
dryzoneAuthor Commented:
Thanks ahoffmann but Nope,I  get an error message
I do
[root@gateway root]# (cat file1 |tr '\012''';cat file2) >file3
and get back the error message
tr: two strings must be given when translating!

Does this really work on your bash shell??
Interesting approach though.
0
 
ahoffmannCommented:
you missed at least 2 blanks in tr command:

  tr '\012' ' '
0
 
dryzoneAuthor Commented:
ahoffmann,
Thanks you solved it.
points are yours.
0
All Courses

From novice to tech pro — start learning today.