Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Is there a way to delete a line in a file?

Jul
5
0
All of these are useful:
@FILECLOSE Close a file handle
@FILEOPEN Open a file handle
@FILEREAD Read next line from a file handle
@FILESEEKL Move a file handle pointer to a specified line
@FILEWRITE Write next line to a file handle
@FILEWRITEB Write data to a file handle
@TRUNCATE Truncate the file at the current position of the file handle pointer.
but none allow me to delete a line in a file?
 
is there something in TPIPE? Or maybe a CUT operation?
 
is there something in TPIPE? Or maybe a CUT operation?
Sure, there's TPIPE's /grep. Use grep type 4 (extract non-matching lines). But you'll have to be able to describe the line you want not extracted uniquely with a regular expression. Below, I remove the "hamster" line.

Code:
v:\> type pets.txt
My dog is black.
My cat is grey.
My hamster is brown.
My bird is green.
My chameleon is green.
My fish have various colors.

v:\> tpipe /input=pets.txt /output=pets.new /grep=4,0,0,0,0,0,0,0,".*hamster.*"

v:\> type pets.new
My dog is black.
My cat is grey.
My bird is green.
My chameleon is green.
My fish have various colors.

v:\>
 
Thanks guys, although is more complex than what would be an equivalent "@FILEREMOVE" !

My need is to manage what is a file-based stack that is shared across many independent sessions and I want to "pop" the top value after it is read. If I logically invert the stack I guess I can use @TRUNCATE to achieve the result I want.
 
If you just want to remove the first line of the file, try
Code:
TAIL /N+1 /N%@LINES[%sourcefile] %sourcefile > %tempfile & MOVE /Q %tempfile %sourcefile
 
if you know the max lines of your file, you can replace the %@lines[] with a number - e.g. 999999. Otherwise, the @lines function has to open the file, iterate over all the lines and count them up. Since you said the first line is the one you want to remove, I would use HEAD instead of TAIL. But in this usage they should behave the same.
Code:
HEAD /N+1 /N 999999 sourcefile
ALIAS RTRUNCATE=`HEAD /N+1 /N 999999 %1 > %1.tmp & MOVE /Q %1.tmp %1`
 
Back
Top
[FOX] Ultimate Translator
Translate