please needing help
I have many text files with lots of lines in them (such as sample.txt)
We have file that has keywords strings (such as match.txt)
Trying to make batch that creates a csv log with matching lines (called log.csv), showing the filename and comma and the whole line that matched any part of the text
I have been trying findstr and fart and sfk
SAMPLE TEXT FILE WITH LINES (filename is "sample.txt")
O say can you see by the dawn's early light
What so proudly we hailed at the twilight's last gleaming
Whose broad stripes and bright stars through the perilous fight
O'er the ramparts we watched, were so gallantly streaming?
And the rockets' red glare the bombs bursting in air
Gave proof through the night that our flag was still there
O say does that star-spangled banner yet wave
O'er the land of the free and the home of the brave
MATCH FILE OF LINES WE WANT TO KNOW ABOUT (filename is "match.txt")
can you see, by the dawn's
Whose broad stripes
bursting in air
So if line in sample.txt has any part of something in the match file match.txt then the whole line goes into the log file called log.csv like this
Notice the filename and then a comma and then the whole line, so we can make csv from it:
sample.txt,O say can you see by the dawn's early light
sample.txt,Whose broad stripes and bright stars through the perilous fight
sample.txt,And the rockets' red glare the bombs bursting in air
I hope this question makes sense to you
matching any part of line in new log csv
Moderator: DosItHelp
Re: matching any part of line in new log csv
You are now the 3rd user that has posted from the same ip address in the past few days.
If you are the same person, please stop making new user names.
If you are the same person, please stop making new user names.
Re: matching any part of line in new log csv
aisha wrote:MATCH FILE OF LINES WE WANT TO KNOW ABOUT (filename is "match.txt")
can you see, by the dawn's
This will not match because it has a comma in the match file but there is not a comma in your sample.txt file.
Re: matching any part of line in new log csv
I changed match.txt to match.log because if match.txt exists in the same directory as your files it will match itself. I also quote surrounded each field because it looks like your data may have commas in it. Quote surrounding will protect this if you are opening the file in Excel.
Might be some other caveats that I am not thinking of. But this should get you what you want based on your example.
Might be some other caveats that I am not thinking of. But this should get you what you want based on your example.
Code: Select all
@echo off
(FOR /F "tokens=1* delims=:" %%G in ('findstr /G:match.log *.txt') DO (
echo "%%G","%%H")
)>log.csv
Re: matching any part of line in new log csv
Yes that made it
on the same IP yes we are two working together on the same team so you have same IP
again my thanks
on the same IP yes we are two working together on the same team so you have same IP
again my thanks