Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Linux merging files

I’m doing a linux online course but im stuck with a question, you can find the question below.

You will get three files called a.bf, b.bf and c.bf. Merge the contents of these three files and write it to a new file called abc.bf. Respect the order: abc.bf must contain the contents of a.bf first, followed by those of b.bf, followed by those of c.bf.

Example
Suppose the given files have the following contents:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a.bf contains +++.

b.bf contains [][][][].

c.bf contains <><><>.

The file abc.bf should then have

+++[][][][]<><><>

as its content.
I know how to merge the 3 files but when i use cat my output is:

+++
[][][]
<><><>

When i use paste my output is "+++ 'a lot of spaces' [][][][] 'a lot of spaces' <><><>"

My output that i need is +++[][][][]<><><>, i dont want the spaces between the content. Can someone help me?

>Solution :

What you want to do is delete the newline characters.

With tr:

cat {a,b,c}.bf | tr --delete '\n' > abc.bf

With echo & sed:

echo $(cat {a,b,c}.bf) | sed -E 's/ //g' > abc.bf

With xargs & sed:

<{a,b,c}.bf xargs | sed -E 's/ //g' > abc.bf

Note that sed is only used to remove the spaces.

With cat & sed:

cat {a,b,c}.bf | sed -z 's/\n//g'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading