LinuxQuestions.org
Register a domain and help support LQ
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 11-09-2010, 08:49 PM   #1
rastin_nz
LQ Newbie
 
Registered: Oct 2010
Posts: 17

Rep: Reputation: 0
updating a text file (replacing the existing parameters with the new values)


Hi everyone;
I have a text file that needs to be updated to be used by some fortran code later.
it looks like that:
1,1 !Ms for y-stations, Ns for x-stations
0,0,0, !xsta, ysta, zsta

I need to replace the "0,0,0" with new values for xsta,ysta and zsta;
I have had no success and ur help is much appreciated.
Sepi

Last edited by rastin_nz; 11-09-2010 at 09:50 PM.
 
Old 11-09-2010, 09:26 PM   #2
adixon
Member
 
Registered: Oct 2010
Posts: 34

Rep: Reputation: 3
need more information on pattern:
is the xsta,ysta,zsta always on the second line? etc.
try post your failed attempt too
 
Old 11-09-2010, 09:42 PM   #3
rastin_nz
LQ Newbie
 
Registered: Oct 2010
Posts: 17

Original Poster
Rep: Reputation: 0
my file name is dc.dat and is a text file;
I want to read another text file containing the coordinates and then replace the first three characters of the second line of dc.dat file , i.e."0,0,0" with the read coordinates
thanks
 
Old 11-09-2010, 10:19 PM   #4
adixon
Member
 
Registered: Oct 2010
Posts: 34

Rep: Reputation: 3
roughly, in c:
->firstline > buffer (using functions fopen,strchr)
->fprintf x,y,z into some_string ('#x#,#y#,#z#,')
->some_string >> buffer (memcpy or strcat)
->rest of file >> buffer (fseek, fread)
->buffer >> newFile (fprintf)
check out http://www.cplusplus.com/reference/clibrary/cstdio/ for excellent c std function reference
if you wanna bash it, others can help with awk or sed
 
Old 11-10-2010, 02:10 AM   #5
rastin_nz
LQ Newbie
 
Registered: Oct 2010
Posts: 17

Original Poster
Rep: Reputation: 0
hi there,
thanks for the help but I need to develope a shell script in linux
sepi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
replacing text in a file graziano1968 Linux - General 4 07-26-2010 06:23 AM
[SOLVED] Variables in text file, how to get their values when printing out the text? idaham Linux - General 2 04-14-2010 03:28 AM
Replacing a line in a text file jeriryan Linux - Newbie 5 06-23-2008 03:56 PM
Replacing words in a text file Raghavan_sat Programming 3 05-27-2008 03:11 PM
replacing text in file kushalkoolwal Programming 17 10-25-2005 05:25 AM


All times are GMT -5. The time now is 03:35 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration