Paste content of a file to another file and make it as columned


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Paste content of a file to another file and make it as columned
# 1  
Old 06-19-2009
Paste content of a file to another file and make it as columned

Pls help me on this. I have to 2 files like shown below:
File 1
TAIJM
AXPKIM
BEMGW

File 2
PXMPA
JYGE
IMJP

What i want to do is to paste both file to a new file on thir format:
File 3
TAIJM PXMPA
AXPKIM JYGE
BEMGW IMJP

I tried cat and print, but it doesn't work. Cn anyone help me on this? Thanks

---------- Post updated at 09:46 AM ---------- Previous update was at 09:44 AM ----------

It should appear to be in column, with space between the two strings. Thanks!
# 2  
Old 06-20-2009
Quote:
Originally Posted by kingpeejay
...
What i want to do is to paste both file to a new file on thir format:
...
Code:
paste file1 file2

tyler_durden
# 3  
Old 06-20-2009
It worked! Thanks a lot. Another questions, for further editing. I want the second column to be align; meaning, their first character is aligned with each other. And there should be a space between them

---------- Post updated 06-21-09 at 03:56 AM ---------- Previous update was 06-20-09 at 08:16 PM ----------

Anyone who can help me further with this one? Thanks in advance
# 4  
Old 06-20-2009
.... | awk '{ printf "%-6s %-7s\n",$1,$2 }' (adjust values according to data)
# 5  
Old 06-20-2009
Can u pls explain that code? And how the output will look like. Thanks!
# 6  
Old 06-20-2009
paste file1 file2| awk '{ printf "%-6s %-7s\n",$1,$2 }'

paste will merge your files tab separated as durden_tyler said and awk will format the output in lines with 2 strings separated by a space, both left alligned, assuming that the first column contains strings not longer than 6 characters and the second one not longer than 7 characters. This is just an example, adjust the length to the "real" data.
# 7  
Old 06-20-2009
Thanks! God bless!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make paste -d second file print down while looping?

]I would like to make the second file label 'b' print down the first file label 'a', like shifting down the file creating new lines I want it to print all the way down until the first line of the second file hit the last line of the first file. Would I have to put this into a file itself or could I... (24 Replies)
Discussion started by: bigvito19
24 Replies

2. Shell Programming and Scripting

Insert content of a file to another file at a line number which is given by third file

Hi friends, here is my problem. I have three files like this.. cat file1.txt ======= unix is best unix is best linux is best unix is best linux is best linux is best unix is best unix is best cat file2.txt ======== Windows performs better Mac OS performs better Windows... (4 Replies)
Discussion started by: Jagadeesh Kumar
4 Replies

3. Shell Programming and Scripting

How to cut a pipe delimited file and paste it with another file to form a comma separated outputfile

Hello ppl I have a requirement to split (cut in unix) a file (A.txt) which is a pipe delimited file into A1.txt and A2.txt Now I have to join (paste in unix) this A2.txt with external file A3.txt to form output file A4.txt which should be CSV (comma separated file) so that third party can... (25 Replies)
Discussion started by: etldev
25 Replies

4. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

5. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

6. Shell Programming and Scripting

Help required the cut the whole contents from one file and paste it into new file

Hi, First of all sincere apologies if I have posted in a wrong section ! Please correct me if I am wrong ! I am very new to UNIX scripting. Currently my problem is that I have a code file at the location /home/usr/workarea/GeneratedLogs.log :- Code :- (Feb 7, 571 7:07:29 AM),... (4 Replies)
Discussion started by: acidburn_007
4 Replies

7. Shell Programming and Scripting

awk read value from file and paste in other file

Hi, I'm working on a perl-awk loop combination and what I want to do is read in the first line of values.exp and pass that value to test1.exp; next, read in the second line of that file and pass that value to test2.exp. Which would mean: values.exp: 1.2 1.4 test1.exp 1 test2.exp... (10 Replies)
Discussion started by: tobias1234
10 Replies

8. Programming

makeutility: how to get the make-file name inside of the make-file?

How I can get the current make-file name in a make-file So, if I run make with specified file:make -f target.mak is it possible to have the 'target' inside of the that 'target.mak' from the file name? (2 Replies)
Discussion started by: alex_5161
2 Replies
Login or Register to Ask a Question