LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2010, 10:16 AM   #1
arvindk.monu
LQ Newbie
 
Registered: Aug 2009
Posts: 22

Rep: Reputation: 0
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
 
Old 07-15-2010, 10:19 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by arvindk.monu View Post
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 ?
 
Old 07-15-2010, 10:24 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
I am with Sergei ... you show us yours and we will help fix it
 
Old 07-15-2010, 11:41 AM   #4
arvindk.monu
LQ Newbie
 
Registered: Aug 2009
Posts: 22

Original Poster
Rep: Reputation: 0
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.
 
Old 07-15-2010, 11:54 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by arvindk.monu View Post
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.
 
Old 07-15-2010, 11:59 AM   #6
arvindk.monu
LQ Newbie
 
Registered: Aug 2009
Posts: 22

Original Poster
Rep: Reputation: 0
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.
 
Old 07-15-2010, 12:47 PM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by arvindk.monu View Post
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 ?
 
Old 07-16-2010, 08:55 PM   #8
arvindk.monu
LQ Newbie
 
Registered: Aug 2009
Posts: 22

Original Poster
Rep: Reputation: 0
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how do I know what a file really is after the command 'file' output "data" ? wubai Linux - Newbie 2 11-12-2012 07:20 PM
where does file system keeps file name in the file system data structure pavan.manipal Linux - Newbie 4 02-22-2010 07:38 AM
Create File Shell Syntax and pass data to the file FirstBorn Linux - General 22 07-31-2008 09:48 PM
gnuplot, pull X data from file, specify Y data at cmd line? hedpe Programming 5 03-15-2007 11:32 PM
How to play a media file/ video file/mp3 file recorded in harddisk/cd-rom arindam Linux - Newbie 2 09-05-2003 10:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration