Delete line 1 to n of a file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 52
- Joined: Mon Apr 06, 2020 1:19 pm
- Location: Thailand
- Contact:
Delete line 1 to n of a file
Hi:
I want to delete the first n lines of a text file.
I can do it by put empty into line 1 to n of URL blah blah blah - which works.
But I've seen online around 2012 this more elegant / clear alternative
delete line 1 to n of URL etc
yet it won't work for me. The file has enough lines. The line above seems very "livecode" simple, elegant, clear.
Does anyone know WHY I can't use it or what I have to do to use it or something like it? I know that I can copy the file into a variable delete the lines and put the variable back, but I'm seeking to be more elegant than that.
The help of the wise and learned - much appreciated on this one.
I want to delete the first n lines of a text file.
I can do it by put empty into line 1 to n of URL blah blah blah - which works.
But I've seen online around 2012 this more elegant / clear alternative
delete line 1 to n of URL etc
yet it won't work for me. The file has enough lines. The line above seems very "livecode" simple, elegant, clear.
Does anyone know WHY I can't use it or what I have to do to use it or something like it? I know that I can copy the file into a variable delete the lines and put the variable back, but I'm seeking to be more elegant than that.
The help of the wise and learned - much appreciated on this one.
Re: Delete line 1 to n of a file
Obviously DELETING is not supported by Lc with the open file... and url("file:"...) syntax.
So you could file an enhancement request here: https://quality.livecode.com
In the meantime you'll have to use what you wrote:
So you could file an enhancement request here: https://quality.livecode.com
In the meantime you'll have to use what you wrote:
BTW: This is exactly what LC does internally when using the url("file:"...) syntax.I know that I can copy the file into a variable delete the lines and put the variable back
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Delete line 1 to n of a file
I would import the text into a field, delete the lines, and then write it back to the file.
Re: Delete line 1 to n of a file
We guessed, Richmond, we guessed.
Re: Delete line 1 to n of a file
If you really want the LiveCode engine to do the lifting you can
(In *all* the cases, you would need to make sure that the file in question is not already opened, either in LiveCode or any other app/editor.)
I'd advise using a better variable name than n though.
Code: Select all
put line (n + 1) to -1 of url("file:" & tFile) into url("file:" & tFile)
I'd advise using a better variable name than n though.
Re: Delete line 1 to n of a file
Very clever, Sir!SparkOut wrote: ↑Sat Jan 28, 2023 1:47 pmIf you really want the LiveCode engine to do the lifting you can(In *all* the cases, you would need to make sure that the file in question is not already opened, either in LiveCode or any other app/editor.)Code: Select all
put line (n + 1) to -1 of url("file:" & tFile) into url("file:" & tFile)
I'd advise using a better variable name than n though.
Re: Delete line 1 to n of a file
well I see that it's not essentially different from the OP's original solution of although I think you would have to cater for line endings and account for a leading CR in the resulting file. (ie there's a blank first line)
Code: Select all
put empty into line 1 to n of URL...
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Delete line 1 to n of a file
Klaus: if you can do something very, very easily (in the way I suggested) why spend donkey's ages on a more complicated way?
Re: Delete line 1 to n of a file
Well, using a variable instead of a field is a tiny bit less complicated, because you do not need to create a field.
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Delete line 1 to n of a file
And working with field text is just about the slowest thing you can do in LC.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Delete line 1 to n of a file
Yerss, well not all of are worried about shaving off a few nanoseconds.
-
- VIP Livecode Opensource Backer
- Posts: 9857
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Delete line 1 to n of a file
But newcomers may wonder why the extra step is added to the instruction when it adds nothing to the operation.richmond62 wrote: ↑Sun Jan 29, 2023 7:25 pmYerss, well not all of are worried about shaving off a few nanoseconds.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: Delete line 1 to n of a file
I think Richmond's solution would be easier for newcomers to grasp, and if you replace "field" with "variable" it's functionally equivalent to what LiveCode does with Craig's version. While Craig's is syntactically concise and fast, it takes a fair bit of nogginwork to unravel.
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev