comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Write to a certain line of a file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Write to a certain line of a file [message #78958 is a reply to message #78957] Thu, 19 January 2012 08:43 Go to previous messageGo to previous message
Mark Piper is currently offline  Mark Piper
Messages: 198
Registered: December 2009
Senior Member
On 1/19/2012 5:18 AM, Brian J. Daniel wrote:
> I haven't done this, but POINT_LUN may do what you want. You'd need
> to know the number of bytes per line. You will still have to read the
> entire line, change the bit you want to change, move the LUN back to
> the beginning of the line, and rewrite it.
>
> OpenR, LUN, filename, /Get_Lun
> Point_Lun, LUN, line_number * bytes_per_line
> tmp=''
> ReadF, LUN, tmp
> ; change the line as you see fit
> new_line = tmp + 'changed line!'
> Point_Lun, LUN, line_number * bytes_per_line
> PrintF, LUN, new_line
> Free_Lun, LUN
>
> Code is UNTESTED!

To add to Brian's idea, if you have a text file, use SKIP_LUN with the
LINES keyword set. A crude example:

pro replace_line_ex
compile_opt idl2

f0 = 'ascii.txt'
f1 = 'ascii-1.txt'
file_copy, file_which(f0), f1, /overwrite

nskip = 7
line = ''
replacement = 'My dog has fleas.'

openu, u, f1, /get_lun
skip_lun, u, nskip, /lines
point_lun, -u, mark
readf, u, line
nchars = strlen(line)
point_lun, u, mark
printf, u, replacement, format='(a-' + strtrim(nchars,2) + ')'
free_lun, u
end

Diff 'ascii.txt' in the example/data directory of the IDL distro with
'ascii-1.txt' in your working directory.

mp
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: confidence level
Next Topic: Write to a certain line of a file

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 16:26:16 PDT 2025

Total time taken to generate the page: 1.52302 seconds