[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

Find text string in *.txt file and include line above plus 2 lines below

Asked by BillDL in MS DOS

Hi Experts

I don't know if this would be possible in a batch file using any of the internal Windows XP CMD commands, or calling any of the SP2/SP3 support tools.  I have a vague recollection of a command or program that locates a text string or a line, or something like that, and ALSO includes a specified number of lines either side of it in the results.  Problem is that I cannot recall whether this was a third party utility (eg. SysInteranls tool) or native Windows program.

What I need to do is find the lines containing asterisks in text files, as in the extract here:

Start Offset: 0x00000000
*** Marker: SOI (xFFD8) ***
  OFFSET: 0x00000000
 
*** Marker: APP1 (xFFE1) ***
  OFFSET: 0x00000002
  length          = 9214
  Identifier      = [Exif]

*** Marker: DQT (xFFDB) ***
  Define a Quantization Table.
  OFFSET: 0x00002402
  Table length = 132

.... BUT, as well as finding the lines with the ***, I also want to capture the line above and two lines below all instances found.  Taking the extract above, I need to capture all  "*** Marker:" lines, any lines immediately above referencing an Offset value, and the lines immediately below the Marker line referencing an Offset value (always the 1st or 2nd line below).  So, I figured that One line above, and Two lines below those lines with asterisks would capture all of what I need, and I can clean up superfluous content afterwards.

Finding the lines containing asterisks and redirecting the found lines in each text file to a new file with the same name, plus a suffix, is the easy part:

for %%a in ("*.txt") do type %%a | find /i "*" >> "%%~ni_Markers.txt"

I've looked at FINDSTR as well as FIND, and it doesn't do what I need either.
I tried to write some nested FOR statements to also search for "offset:", but got totally lost in the spaghetti code.

Some of the *.txt files run to over 400 pages at size 10 font when pasted into MS Word, so this should give you an idea why it's not really feasible to manually scroll through a number of text files and delete content, even though 95% of the content comprises huge blocks of unwanted content.

At a wild guess, a VBS file might be able to do this on its own, or even by calling and using an MS Word document with a Macro to do the dirty work, but I had hoped there might be a more fluent way using a standalone utility program.

Does anybody know of a method to INCLUDE a pre-defined number of adjacent lines with the line containing the text string searched for?

Thanks
Bill
[+][-]12/13/08 07:25 PM, ID: 23166410Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: MS DOS
Sign Up Now!
Solution Provided By: Superdave
Participating Experts: 2
Solution Grade: A
 
[+][-]12/14/08 06:59 AM, ID: 23167822Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/15/08 01:27 AM, ID: 23171980Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/15/08 08:00 AM, ID: 23174565Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/15/08 08:11 AM, ID: 23174720Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/15/08 08:20 AM, ID: 23174825Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/15/08 09:28 AM, ID: 23175655Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/15/08 10:55 AM, ID: 23176519Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]12/17/08 03:41 AM, ID: 23192309Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_EXPERT_20070906