Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove line from text file.

Status
Not open for further replies.

dinoviapangea

Technical User
Apr 9, 2002
41
US
I have a file in the following format,

test1a|test1b|test1c|test1d
test2a|test2b|test2c|test2d
test3a|test3b|test3c|test3d
test4a|test4b|test4c|test4d

How can I remove an entire line, test2. The file is pipe delimited with no spaces. I want to be able to enter test2c and delete the entire line without affecting the other lines.

Thanks
 
try using List(file) with Chr(10) as delimiter Sylvano
dsylvano@hotmail.com
 
You would use the ListContains() function and the ListDeleteAt() function with the Chr(10) delineator

=== START CODE EXAMPLE ===
[COLOR=666666]<!--- Read File into variable --->[/color]
<cffile action=&quot;READ&quot;
file=&quot;myFile.txt&quot;
variable=&quot;file&quot;>


[COLOR=666666]<!--- Remove Line with &quot;test2f&quot; --->[/color]
<cfscript>
vRow = ListContains(file, &quot;test2f&quot;, Chr(10));
if(vRow) [COLOR=666666]// if vRow is not 0, then delete the line[/color]
file = ListDeleteAt(file, vRow, Chr(10));
</cfscript>

[COLOR=666666]<!--- Write new list to file --->[/color]
<cffile action=&quot;WRITE&quot;
file=&quot;myFile.txt&quot;
output=&quot;#file#&quot;>

=== END CODE EXAMPLE ===

Be sure to use proper file locking with <CFLOCK> - tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top