file merge


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers file merge
# 1  
Old 12-13-2008
file merge

Hi,

I have 3 files. The containts of the files are as followes.

File 1:

1
2
3

File 2:
A
B
C

File 3:
Ind
US
Aus

I want to merge the above file and the resultant file would be
1 A Ind
2 B US
3 C Aus

Please suggest how can I achieve this.

Thanks.
# 2  
Old 12-13-2008
You can use the join command to join two files together then you can join the combined files with the 3rd file.

Join file1 file2 > file12
join file12 file3 > file4

file 4 being the combined file.
# 3  
Old 12-13-2008
Sorry that's going to work the way you want to. I'll look into it some more
# 4  
Old 12-13-2008
With awk:

Code:
awk '
FILENAME=="file1"{s[++i]=$0 FS}
FILENAME=="file2"{s[++j]=$0 FS}
FILENAME=="file3"{print s[++k] FS $0}' file1 file2 file3

Use nawk or /usr/xpg4/bin/awk on Solaris if you get errors.

Regards
# 5  
Old 12-13-2008
try this
sh-3.2$ awk '{ getline line2 < "file2";getline line3 < "file3"; print $0" "line
2" "line3}' file1
1 A Ind
2 B US
3 C Aus
# 6  
Old 12-15-2008
use paste command, refer man for more details
Quote:
paste file1 file2 file3
# 7  
Old 12-15-2008
Thank you all for your response.
Specially thanks to Yogi Raj for letting me know the paste command. It works as per my requirement.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk can't open file; file merge attempt

Dear all, I have an AWK related issue. I have two data files; the first, FileA has fewer lines, the second, FileB has more. FileA is a subset of FileB . Both files are tab delimited. What I want to do? When the first two columns for FileA match the first two columns of FileB, I want to... (4 Replies)
Discussion started by: A_Human_Person
4 Replies

2. UNIX for Beginners Questions & Answers

Match and Merge two file

Hi All, I have two file . I need to merge both file based on a match. File 1: Column1 column2 column3 column4 File 2: column3 column5 I need to combine the two file based on match , Which in my case is column3 and combine the file as below Combined file Column1 (10 Replies)
Discussion started by: arunkumar_mca
10 Replies

3. UNIX for Dummies Questions & Answers

How to merge two files into third file?

Hi All, i have a requirement as below. There are two files. In 1st file a.txt i have four lines as below Ramesh Suresh Pradeep Franklin In 2nd file b.txt i have 5 lines as below Francis Elizabeth David John Ravi The output file suppose c.txt should contain 1st line of... (5 Replies)
Discussion started by: sureshk_85
5 Replies

4. UNIX Desktop Questions & Answers

Merge Last Word to Another File

Hi, Im a newbie to scripting. I have a file that looks like the one below. How can i change the last "/" to become a space. Thank You so Much for the help. :) hostname date Feb-9 /u100/DEVCO/Patching/a.log hostname date Jun-25 /u100/DEVCO/DumpCleaner/a.log hostname date Jun-25... (2 Replies)
Discussion started by: lienyca
2 Replies

5. Shell Programming and Scripting

Merge two files into one file

Hi, I need help with merging two files. My requirement is as below: File 1: MachineA MachineB File 2: Process1 Process2 Desired File: MachineA Process1 MachineB Process2 If file 2 contains only one entry Process1, then second line in the desired output should be: MachineA Process1... (1 Reply)
Discussion started by: chiru_h
1 Replies

6. Shell Programming and Scripting

merge two file

how to merge two file, i have 2 input file; file_1 & file_2, so i want the output file_3 as below file_1 NAME aa 111 222 bb.txt 111 222 cc 111 111 dd 222 ee 111 222 (4 Replies)
Discussion started by: zulabc
4 Replies

7. Programming

Merge files from /etc to one file using C

Hi guys, I have a question which might be easy to answer but I don't how to do it. The thing is I need to make a program in C which creates a file with all the content from the files in \etc. I'm not new to C language but to UNIX. I've read somewhere I need to use functions like f_read... (2 Replies)
Discussion started by: sussil
2 Replies

8. Shell Programming and Scripting

[Bash]Attempting to Merge text from one file into another file at the line directly under a word

Hello, This is my first post on the forums. So I want to start by thanking anyone who is kind enough to read this post and offer advise. I hope to be an active contributor now that I've found these forums. I have an issue that I figure would be a good first post.. I have 2 text files... (5 Replies)
Discussion started by: efciem
5 Replies

9. Shell Programming and Scripting

two file merge with awk

Help I read a file that has 2 fields. look for in a second file the first field and update it with the second field of first file. file1 1131518fat11416.txt ../newaod/2001/04/2001-04-00129233-1.txt file2 INSERT INTO tabric VALUES... (2 Replies)
Discussion started by: mcarlo65
2 Replies

10. Shell Programming and Scripting

merge two files in one file

All, I've basic knowlege on understanding UNIX Shell Programming. Right now I need to write a script for the following requirement. Kindly help me or suggest me how to write a Shell script. I've 8 .csv files that are containing "Detail" records. Each file getting more than 1 million. Another... (3 Replies)
Discussion started by: nvkuriseti
3 Replies
Login or Register to Ask a Question