Home: Perl Programming Help: Beginner:
String Replacement in a text file



lokesh_nr
New User

Mar 24, 2015, 9:40 PM


Views: 25961
String Replacement in a text file

Hi Team,

This is one of the nice forums I have seen and need a quick help with perl code. I am taking a list of files in a directory and placing them in a file called files_2_delete.txt file. I want a code to run through the file, add 'del " ' in the beginning of the line and place " in the end of the line.

Sample file entries:

c:\SQL Backup\Trans1.trn
c:\SQL Backup\Trans2.trn
c:\SQL Backup\Trans3.trn
c:\SQL Backup\Trans4.trn

Output:

del "c:\SQL Backup\Trans1.trn"
del "c:\SQL Backup\Trans2.trn"
del "c:\SQL Backup\Trans3.trn"
del "c:\SQL Backup\Trans4.trn"

Thanks
Lokesh


FishMonger
Veteran / Moderator

Mar 25, 2015, 7:13 AM


Views: 25960
Re: [lokesh_nr] String Replacement in a text file

What have you tried?

What errors/warnings are you receiving?

How is the resulting text file going to be used? Is it going to be used in a batch file which executes each of those lines, or is it going to be used in a perl script to do the same thing?

IMO, adding the del to these lines is unnecessary since perl has the unlink function for deleting files.


Laurent_R
Veteran / Moderator

Mar 25, 2015, 10:47 AM


Views: 25928
Re: [lokesh_nr] String Replacement in a text file

Yeah, since you have the list of files in your Perl program, why don't you simply delete the file in this program? It seems so much simpler.