Replacing column with column of another file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Replacing column with column of another file
# 1  
Old 06-24-2008
Replacing column with column of another file

Hi, I have two input files.

File1:

ID Name Place
1-234~name1~Newyork
1-34~name2~Boston
1-2345~name3~Hungary

File1 is a variable length file where each column is seperated by delimitter "~".

File2:

ID Country
1-34<<11 SPACES>>USA<<7 spaces>>
1-234<<10 SPACES>>UK<<8 spaces>>

File2 is a fixed length file where Id is of 15 characters length and Country is of 10 characters length.

I need an output file such that based on ID file1 and file2 should be compared and Place column in file1 should be replaced by country column.

Output File:

ID Name Country
1-234~name1~UK
1-34~name2~USA

Thanks in advance.
# 2  
Old 06-25-2008
Same question here: https://www.unix.com/shell-programmin...idth-file.html

No cross-posting. Read the rules.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing a column in a file with a value

Hi , Could anyone help me for the below request . Suppose i have the data like below : 00006139 2066522 DURTS S 0 20121219 20121219 20121120 00006137 2515401 DURTS S 0 20121219 20121219 20121120 00004363 6030777 DURTS S 0 20121219 20121219 ... (2 Replies)
Discussion started by: Ravi Tej
2 Replies

2. Shell Programming and Scripting

Awk: Need help replacing a specific column in a file by part of a column in another file

Hi, I have two input files as File1 : ABC:client1:project1 XYZ:client2-aa:project2 DEF:client4:proj File2 : client1:W-170:xx client2-aa:WT-04:yy client4:L-005A:zz Also, array of valid values can be hardcoded like Output : ABC:W:project1 XYZ:WT:project2 (1 Reply)
Discussion started by: aa2601
1 Replies

3. UNIX for Dummies Questions & Answers

Replacing a specific column of a text file with another column

Hi, I have a text file in the following format: Code: 13412 NA06985 0 0 2 46.6432798439 4 4 4 4 13412 NA06991 NA06993 NA06985 2 48.8478948517 4 4 2 4 13412 NA06993 0 0 1 45.8022601455 4 4 2 4 13401 NA06994 0 0 1 48.780669145 4 4 4 4 13401 NA07000 0 0 2 47.7312017846 2 4 4 4 ... (2 Replies)
Discussion started by: evelibertine
2 Replies

4. UNIX for Dummies Questions & Answers

Replacing a specific column of a text file with another column

I have a text file in the following format: 13412 NA06985 0 0 2 46.6432798439 4 4 4 4 13412 NA06991 NA06993 NA06985 2 48.8478948517 4 4 2 4 13412 NA06993 0 0 1 45.8022601455 4 4 2 4 13401 NA06994 0 0 1 48.780669145 4 4 4 4 13401 NA07000 0 0 2 47.7312017846 2 4 4 4 13402 NA07019... (3 Replies)
Discussion started by: evelibertine
3 Replies

5. Shell Programming and Scripting

Replacing a column in a file

Hi, I want to replace a column in a file with a file that only has one column. Reading another post this is what I'm trying to do, The existing file has n columns and I paste the extra column using the paste command to make it n+1 paste file1 file2 > file3 Firstly I want to now remove... (3 Replies)
Discussion started by: lost.identity
3 Replies

6. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

7. Shell Programming and Scripting

Replacing column with another column of different file by awk

Hi All, I will really appreciate if you kindly lookinto my requirement below and provide me a solution First file format test1.txt qq ww rr tt ee ff qq ww rr tt ee ff Second file format text2.txt aa aa Now o/p I want as text1.txt's 4th column replaced... (5 Replies)
Discussion started by: Pratik4891
5 Replies

8. UNIX for Dummies Questions & Answers

Replacing a column in a text file

Say I had a text file that contained four columns, like the following: Mack Christopher:237 Avondale Blvd:970-791-6419:S Ben Macdonor:30 Dragon Rd:647-288-6395:B I'm making a loop that will replace the fourth column a line in the file with the contents of a variable 'access', but I have no... (6 Replies)
Discussion started by: Sotau
6 Replies

9. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

10. UNIX for Dummies Questions & Answers

Replacing column with column of another file

Hi, I have two input files. File1: ID Name Place 1-234~name1~Newyork 1-34~name2~Boston 1-2345~name3~Hungary File1 is a variable length file where each column is seperated by delimitter "~". File2: ID Country 1-34<<11 SPACES>>USA<<7 spaces>> 1-234<<10 SPACES>>UK<<8 spaces>> ... (1 Reply)
Discussion started by: manneni prakash
1 Replies
Login or Register to Ask a Question