Re: Single Line replacement in file
- From: "Michael Bruschkewitz" <brusch4_removethis@xxxxxxx>
- Date: Wed, 30 Jul 2008 13:09:54 +0200
"Raveendran Jazzez" <jazzezravi@xxxxxxxxx> schrieb im Newsbeitrag
news:a65c4c849abcc50137362cbcfd7a8936@xxxxxxxxxxxxxxxxx
My need:
code.rb --> out contains my proper output. But i didn't able to
overwrite the same line in file.It means
1. single --> "wordpress.com/tag/<B>jazzez</B>/ - 11k - "
2. out4 --> "wordpress.com/tag/jazzez"
Here i want to replace the first line in hi.txt file 1 to 2.
You can't replace "lines" in a file because file on disk doesn't know about
lines.
You can read one file, filter its content, write into another file, close
first file, close second file, delete first file or rename to backup, rename
second file to first file.
This would be the easiest way.
or
You read complete file into memory, filter there, seek to file start, write
contents from memory, resize.
More dangerous on errors.
or
You replace characters of these tags by spaces directly in the file, may be
possible but needs more repositioning in file.
I also would recommend to analyze the XML-tree instead of simply removing
the tags wherever found.
Use, for example, "rexml" as contained in Ruby 1.8.
.
- Follow-Ups:
- Re: Single Line replacement in file
- From: jazzez ravi
- Re: Single Line replacement in file
- References:
- Single Line replacement in file
- From: Raveendran Jazzez
- Single Line replacement in file
- Prev by Date: Re: insert 10 line of code in .doc file
- Next by Date: Re: libxml: is it possible not to use doctype declaration?
- Previous by thread: Single Line replacement in file
- Next by thread: Re: Single Line replacement in file
- Index(es):
Relevant Pages
|