LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to use Data of one file in another file??? (https://www.linuxquestions.org/questions/programming-9/how-to-use-data-of-one-file-in-another-file-819986/)

arvindk.monu 07-15-2010 10:16 AM

How to use Data of one file in another file???
 
Hello People,

I have two file file1.txt file2.txt,both file have content like following

file1.txt

Voltage and current behavior for diodes.
v1 2 3 dc 5v
Voltage and current behavior for transistor
v2 4 5 dc 6v
Voltage and current behavior for FET
v3 6 7 dc 2v
M.Tech(VLSI) in NIT jaipur
Simulation for V-I behaviour


file2.txt

2
3
4



the number in last coloumn of file1.txt should be replaced by number in file2.txt as follows,changes should be happened in line containg vn,n is integer e.g:1,2,3.........8....99...n.Result.txt file should look like as result.txt

result.txt

Voltage and current behavior for diodes.
v1 2 3 dc 2v<-----2 is coming from file2.txt
Voltage and current behavior for transistor
v2 4 5 dc 3v<-----3 is coming from file2.txt
Voltage and current behavior for FET
v3 6 7 dc 4v<-----4 is coming from file2.txt
M.Tech(VLSI) in NIT jaipur
Simulation for V-I behaviour


Thanks in advance

Thanks and Regards

Sergei Steshenko 07-15-2010 10:19 AM

Quote:

Originally Posted by arvindk.monu (Post 4034088)
Hello People,

I have two file file1.txt file2.txt,both file have content like following

file1.txt

Voltage and current behavior for diodes.
v1 2 3 dc 5v
Voltage and current behavior for transistor
v2 4 5 dc 6v
Voltage and current behavior for FET
v3 6 7 dc 2v
M.Tech(VLSI) in NIT jaipur
Simulation for V-I behaviour


file2.txt

2
3
4



the number in last coloumn of file1.txt should be replaced by number in file2.txt as follows,changes should be happened in line containg vn,n is integer e.g:1,2,3.........8....99...n.Result.txt file should look like as result.txt

result.txt

Voltage and current behavior for diodes.
v1 2 3 dc 2v<-----2 is coming from file2.txt
Voltage and current behavior for transistor
v2 4 5 dc 3v<-----3 is coming from file2.txt
Voltage and current behavior for FET
v3 6 7 dc 4v<-----4 is coming from file2.txt
M.Tech(VLSI) in NIT jaipur
Simulation for V-I behaviour


Thanks in advance

Thanks and Regards

The answer to your question: through a program.

Which programming languages do you know and what code have you written so far ?

grail 07-15-2010 10:24 AM

I am with Sergei ... you show us yours and we will help fix it

arvindk.monu 07-15-2010 11:41 AM

Hi Sergei I know C/C++ and Shell scripting but i am just a beginner like.i want to do my work in Shell script.

I wrote this

awk '{getline s < "file2.txt"; $NF=s"v"}1' file1.txt

but it is not working for me...Can please help me in correcting it or give me another solution for my problem in shell script or using AWK.I will be very thankful to you.

Sergei Steshenko 07-15-2010 11:54 AM

Quote:

Originally Posted by arvindk.monu (Post 4034219)
Hi Sergei I know C/C++ and Shell scripting but i am just a beginner like.i want to do my work in Shell script.

I wrote this

awk '{getline s < "file2.txt"; $NF=s"v"}1' file1.txt

but it is not working for me...Can please help me in correcting it or give me another solution for my problem in shell script or using AWK.I will be very thankful to you.

First describe in English how you would do this using your eyes, fingers and using as work media pieces of paper.

arvindk.monu 07-15-2010 11:59 AM

now i am using this

awk '/^v/{getline s < "file2.txt"; $NF=s"v"}1' file1.txt

it is giving my result.Can you please give some other solution for the same.thanks....you guys are very helping.

Sergei Steshenko 07-15-2010 12:47 PM

Quote:

Originally Posted by arvindk.monu (Post 4034238)
now i am using this

awk '/^v/{getline s < "file2.txt"; $NF=s"v"}1' file1.txt

it is giving my result.Can you please give some other solution for the same.thanks....you guys are very helping.


Does it work or not ?

arvindk.monu 07-16-2010 08:55 PM

Hi sergei,

i am getting my result from this

awk '/^v/{getline s < "file2.txt"; $NF=s"v"}1' file1.txt

if i will face problem i will contact you people.for now problem has been resolved.Thanks for your support.


All times are GMT -5. The time now is 05:50 PM.