“Raveendran J.” [email protected] schrieb im Newsbeitrag
code.rb --> out contains my proper output. But i didn’t able to
overwrite the same line in file.It means
- single --> "wordpress.com/tag/jazzez/ - 11k - "
- 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
You can read one file, filter its content, write into another file,
first file, close second file, delete first file or rename to backup,
second file to first file.
This would be the easiest way.
You read complete file into memory, filter there, seek to file start,
contents from memory, resize.
More dangerous on errors.
You replace characters of these tags by spaces directly in the file, may
possible but needs more repositioning in file.
I also would recommend to analyze the XML-tree instead of simply
the tags wherever found.
Use, for example, “rexml” as contained in Ruby 1.8.