How to delete a given line in a text file?
How to remove the 1st line in a txt file?
How to delete a given line in a text file?
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How to delete a given line in a text file?
Here is some code that will work for you:
Usage: DELLINE <infile> <outfile> <linenumber>
DelLine.Prg:
DelLine.xpj:
Usage: DELLINE <infile> <outfile> <linenumber>
DelLine.Prg:
Code: Select all
#INCLUDE "dcdialog.CH"
FUNCTION Main( cInFile, cOutFile, cLineToDelete )
LOCAL nHandle1, nHandle2, aText[0], cLine, nLineToDelete, nLine
nLineToDelete := Val(cLineToDelete)
nHandle1 := DC_TxtOpen(cInFile)
nHandle2 := FCreate(cOutFile)
nLine := 1
DO WHILE !DC_TxtEof(nHandle1)
cLine := DC_TxtLine(nHandle1)
IF nLineToDelete <> nLine
FWrite(nHandle2,cLine+Chr(13)+Chr(10))
? cLine
ELSE
? '<<<<<<<< Line ' + cLineToDelete + ' has been deleted >>>>>>>>>'
ENDIF
DC_TxtSkip(nHandle1)
nLine++
ENDDO
FClose(nHandle1)
FClose(nHandle2)
wait
RETURN nil
Code: Select all
[PROJECT]
COMPILE = xpp
COMPILE_FLAGS = /q /w /rDCLIPX.LIB
GUI = yes
LINKER = alink
DelLine.XPJ
[DelLine.XPJ]
DelLine.EXE
[DelLine.EXE]
DelLine.PRG
The eXpress train is coming - and it has more cars.
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How to delete a given line in a text file?
Thank You, Roger! I have the following code. It works correctly, except at the beginning of the file is an empty string, which is unnecessary.
[/size]
An example of the resulting file:
Code: Select all
mFileName = SUBSTR(aFileName[ff], 1, AT('.',aFileName[ff])-1)
CLOSE ALL
USE (mFileName) EXCLUSIVE NEW
SELECT (mFileName)
********** Открыть процесс печати выходной формы
set device to printer
set printer on
set printer to (mFileName+'.csv')
set console off
?'SK_ID_CURR,TARGET'
DBGOTOP()
DO WHILE .NOT. EOF()
?ALLTRIM(ID)+','+ALLTRIM(STR(ROUND(PROB,1)))
DBSKIP(1)
ENDDO
********** Закрыть процесс печати выходной формы
Set device to screen
Set printer off
Set printer to
Set console on
An example of the resulting file:
Code: Select all
SK_ID_CURR,TARGET
100001,0.9
100005,0.8
100013,0.7
100028,0.3
100038,0.8
100042,0.5
100057,0.8
100065,0.7
100066,0.7
100067,0.8
100074,0.8
100090,0.8
100091,0.8
-
- Posts: 484
- Joined: Wed Jan 27, 2010 10:25 pm
- Location: Berlin Germany
Re: How to delete a given line in a text file?
Change ?'SK_ID_CURR,TARGET' to ??'SK_ID_CURR,TARGET'
_______________________
Best Regards
Wolfgang
Best Regards
Wolfgang
- Eugene Lutsenko
- Posts: 1649
- Joined: Sat Feb 04, 2012 2:23 am
- Location: Russia, Southern federal district, city of Krasnodar
- Contact:
Re: How to delete a given line in a text file?
Thank you Roger and Wolfgang for the great tips!
Everything worked out great.
And I apologize for the fact that I can not always clearly and concretely formulate the question. But a good question is already part of the answer. And when you do not know the answer, and the question is clearly difficult to formulate.
Everything worked out great.
And I apologize for the fact that I can not always clearly and concretely formulate the question. But a good question is already part of the answer. And when you do not know the answer, and the question is clearly difficult to formulate.