Link to home
Start Free TrialLog in
Avatar of Joesephlebon
Joesephlebon

asked on

Batch file to comment specific lines into a text file

Hi Experts,

Happy cristmas for all, and hope we find all the happiness, health and money (lotof money $$$)  :D

Please, i need to do a batch file like that :

MyBatchFile.bat    file.txt    FileWithLineToComment.txt

Where :

FileWithLineToComment.txt
     it's a text file, this one containall the lines text (not numbers of line) that we need to comment.

MyFile.txt:
   Containe all the lines

MyBatchFile.bat
   Is the program that i need to write. This batch file will :
  1- open FileWithLineToComment.txt, and read line by line
  2- for each line we read, we will search it into the "MyFile.txt"
  3- one time we find it we will add " // " in the first of the find line, and like that it will be
comment.
 


Exemple :

MyFile.txt Containe :
123
34
12
153
123
757

Open in new window

FileWithLineToComment.txt
12
757

Open in new window


if i do this command line :
MyBatchFile.bat    file.txt    FileWithLineToComment.txt

Open in new window


MyFile.txt   will be like that:
 
123
34
//12
153
123
//757

Open in new window


Hope you can help me

Thanks
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Are these real world examples, or are they going to be text files with any amount of data, words, spaces, commas, other characters potentially on the line.  Same for the list of lines to check?

Are there any blank lines etc. in the file that are important?

And just to check it seems you are checking the whole line to comment, i.e. if your string was found part way across the line.

If all of those end up being just like your answer it is a relatively simple for loop but no point writing that if not.

thanks

Steve
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Joesephlebon
Joesephlebon

ASKER

Thanks so much Experts ;)
It's work fine :)
Welcome, glad that was useful.

~bp