?
Solved

bash programming question

Posted on 1999-07-03
7
Medium Priority
?
264 Views
Last Modified: 2010-03-18
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.
0
Comment
Question by:dryzone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Expert Comment

by:lewis_loo
ID: 1585584
how about this:

cat file1+file2 > file3
0
 
LVL 1

Expert Comment

by:lewis_loo
ID: 1585585
I do a mistake so this is the answer

cat file1 file2 > file3

how about this?
0
 
LVL 1

Author Comment

by:dryzone
ID: 1585586
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 1585587
(cat file1|tr '\012' ' '; cat file2) > file3
# note that this replaces all newlines, but you gave a file with only one line ;-)
0
 
LVL 1

Author Comment

by:dryzone
ID: 1585588
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 1585589
you missed at least 2 blanks in tr command:

  tr '\012' ' '
0
 
LVL 1

Author Comment

by:dryzone
ID: 1585590
ahoffmann,
Thanks you solved it.
points are yours.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question