How to copy Content of a file to another file on a specific column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to copy Content of a file to another file on a specific column
# 1  
Old 08-13-2009
How to copy Content of a file to another file on a specific column

Hi i have a file (file1)with this content:

1.2.3.10.in-addr.arpa

and a second file (file2) with a content wich have 8 Columns

if a do a

awk '{print $8}' file2

i become this output:

,'10.3.2.1.',

So i want to replace only the 10.3.2.1. in file2 (column 8) with the information off file1 (1.2.3.10.in-addr.arpa)

so the result is ,'1.2.3.10.in-addr.arpa',

Can anybody telme what i have to do? Maybe with awk
# 2  
Old 08-13-2009
Do the files only have one entry or is this just an example? If there are more than one, is the only way to determine the replacement the reversed IP? Can you post a representative sample (more than one line) of what you have and what you want?
# 3  
Old 08-13-2009
something like this:
Code:
$more file2
colum1 colum2 colum3 colum4 colum5 colum6 colum7 colum8 colum9
$awk '{$8="1.2.3.10.in-addr.arpa"; print $0 }' file2
colum1 colum2 colum3 colum4 colum5 colum6 colum7 1.2.3.10.in-addr.arpa colum9

# 4  
Old 08-14-2009
Hi, thank you for the reply.

The file2 contains commands for mysql (generated with a converting tool):
Quote:
insert into records (domain_id, name,type,content,ttl,prio) select id ,'10.3.2.1.', 'PTR', 'nameofserver.', 172800, 0 from domains where name='in-addr.arpa';
insert into records (domain_id, name,type,content,ttl,prio) select id ,'10.3.2.2.', 'PTR', 'nameofserver.', 172800, 0 from domains where name='in-addr.arpa';
.
.
.
.
.
insert into records (domain_id, name,type,content,ttl,prio) select id ,'10.3.2.254.', 'PTR', 'nameofserver.', 172800, 0 from domains where name='in-addr.arpa';
insert into records (domain_id, name,type,content,ttl,prio) select id ,'10.3.2.255.', 'PTR', 'nameofserver.', 172800, 0 from domains where name='in-addr.arpa';
And file1 has only one column:

Quote:
1.2.3.10.in-addr.arpa
2.2.3.10.in-addr.arpa
3.2.3.10.in-addr.arpa
.
.
.
253.2.3.10.in-addr.arpa
254.2.3.10.in-addr.arpa
255.2.3.10.in-addr.arpa
Both files have 255 lines.

What i need is the file2 like this:

Code:
insert into records (domain_id, name,type,content,ttl,prio) select id ,'1.2.3.10.in-addr.arpa', 'PTR', 'nameofserver.', 172800, 0 from domains where name='in-addr.arpa';
insert into records (domain_id, name,type,content,ttl,prio) select id ,'2.2.3.10.in-addr.arpa', 'PTR', 'nameofserver.', 172800, 0 from domains where name='in-addr.arpa';
.
.
.

# 5  
Old 08-14-2009
You need to read de file1?
I see that the unic modification is de one of then number in IP i think that is this the pattern and the file1 is in order 1,2,3,4,5 you don't need to read all the registrys of this file you only need the IP range.


awk 'BEGIN {conta=1} {$8=conta".2.3.10.in-addr.arpa"; conta++;print $0 }' file12
# 6  
Old 08-14-2009
Hi Thank you for the reply.

You are right. Its Enough to do it how do describe.

If i do it how you describe i became this in file12:

Quote:
.
.
.
insert into records (domain_id, name,type,content,ttl,prio) select id 240.2.3.10.in-addr.arpa 'PTR', 'nameofserver.', 3600, 0 from domains where name='in-addr-arpa';
insert into records (domain_id, name,type,content,ttl,prio) select id 241.2.3.10.in-addr.arpa 'PTR', 'nameofserver.', 3600, 0 from domains where name='in-addr-arpa';
insert into records (domain_id, name,type,content,ttl,prio) select id 242.2.3.10.in-addr.arpa 'PTR', 'nameofserver.', 3600, 0 from domains where name='in-addr-arpa';
.
.
.
Thats cool. I am convinced to learn awk in the furure. Now i have to be see how i can insert the ,' bevor and ', behind the reverse IP Adress. Because mysql need it. So that i have a output like this:

Quote:
insert into records (domain_id, name,type,content,ttl,prio) select id ,'242.2.3.10.in-addr.arpa', 'PTR', 'nameofserver.', 3600, 0 from domai
ns where name='in-addr-arpa';
Any ideas?
# 7  
Old 08-14-2009
Code:
awk '{$8="," q "1.2.3.10.in-addr.arpa" q ","; print $0 }' q="'" file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy the content from txt file and create a html file

I have a txt file with a list of error messages in a xml tag format, and each error message is separated with a identifier(endresult).Need to split that and copy and create a new html file.Error message has some special character. how to escape the special character and insert my data into the... (7 Replies)
Discussion started by: DevAakash
7 Replies

2. Shell Programming and Scripting

Appending content of a file to another file before a specific character

Hi there, i've got a file with this content $ cat file1 Matt Mar The other file has the same number of lines with this content: $ cat file2 20404=767294 23450=32427 is there a way with either using sed, awk or paste to insert the content of file1 before the "=" character? So... (3 Replies)
Discussion started by: nms
3 Replies

3. UNIX for Beginners Questions & Answers

Insert content from file 1 to file 2 in specific criteria meet

Hi , I'm looking for some code that can copy and paste form file1 to file2 with 2 criterial meet. file1: test "sp-j1" test "sp-j2" test "sp-j3" test "sp-j4" file2: sub Pre_Shorts1 (Status_Code, Message$) global Status !if Message$ <> "" then print... (3 Replies)
Discussion started by: kttan
3 Replies

4. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

5. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

6. Shell Programming and Scripting

Adding content of two file in a single file column wise

Hi, I am trying to get the file in particular pattern using shell script. I have to add one column to some other file. For example consider two file as below. File1: name1 name2 name3 File2: Add1 age1 Add2 age2 Add3 age3 I want this two file in a single file format something like... (3 Replies)
Discussion started by: diehard
3 Replies

7. 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

8. UNIX for Dummies Questions & Answers

How to copy entire file content into another file being in last line mode of vi ?

How to copy entire file content into another file being in last line mode of vi ? ---------- Post updated at 10:07 AM ---------- Previous update was at 09:56 AM ---------- Got it : :1,30w file.txt (1 Reply)
Discussion started by: presul
1 Replies

9. Shell Programming and Scripting

Bash copy file contents into an existing file at a specific location

Hi all I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far: File A line 1 line 2 line 3 line 4 ... (6 Replies)
Discussion started by: gshepherd7
6 Replies

10. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies
Login or Register to Ask a Question