Search for specifc words in huge log files or txt files
So you have a text/log file which is about 200MB? 800MB? 1GB? 2GB? Ok the data is in there, but how you gonna search for what you want? Now what if I have about 100 files 2GB each? Oops…
This is a must know, coz you may never know when you will need this.
To resolve: The process tried to write to a nonexistent pipe. –> Run this from Powershell and not cmd
Say I have about 300 log files named u_1000.log, u_1001.log, u_1002.log …. u_1300.log and I need to find out all entries which has the text “Ratish” in it.
- Open cmd/powershell
- Navigate to the location of the log file
-
Type the command:
type u*.log |find /i “word to search” >> c:tempoutput.txt
Here:
type – This is a part of the command and I am not asking you to “Type”
u*.log – You need to specify if the log file is *.log or *.txt. u*.log is the name of the log file sequence like shown above. If you specify u*.log, it will search for the keyword in all files starting with alphabet ‘u’ residing in the location specified.
“word to search” is the word you are searching in the logs. In this case Ratish
When this command is completed, you will get a txt file with the contents in the log file with the “word” you searched for.
Note: 1. At the start of the command there is a type and this should be included while running this.
2. The command prompt should be navigated to the location where the log files reside.
3. Most imp – RUN AS ADMINISTRATOR (dont ask me why… lol)
Ratish Nair
MVP Exchange
Team@ MSExchangeGuru
Keywords: Search for a text in a txt file, search huge text file, search huge log files, query huge logfiles, search for a name in a txt file, searching text files, parsing txt or log files
June 20th, 2011 at 11:02 am
Man – You are awesome. Im working with Windows for a long time and nvr knew this.
Thank you a lot.
June 27th, 2011 at 7:48 am
Think this will work just as well (without the “type” command in there)
find “corrupt” /i log.* >> corrupt.txt
June 28th, 2011 at 8:23 pm
See, we learn something new everyday… Thanks Neeraj.
July 27th, 2011 at 8:13 am
Hi,
can we search the messages in the Log files ( exchange log files) insted of GUI.
Thanx
Muthu
August 7th, 2011 at 2:14 pm
Nice tip dude.
September 21st, 2012 at 3:34 am
Ratish
I seen most of your articles and now am forced to say ” You are amazing”
Thanks a lot
February 5th, 2014 at 4:25 pm
I…like it. Had problem with double quotes, so may have to type out @ prompt, but excellent tip!
July 17th, 2016 at 4:49 am
it worked perfectly. Is there a way to make it look for more than one word
July 17th, 2016 at 4:53 am
That will be a phrase. It has to be together.
July 17th, 2016 at 6:13 am
Also does this grab the line of text attached to what you search for if you are looking in a text file