?
Solved

Need set of dos commands to generate code for each line in text file

Posted on 2013-11-25
5
Medium Priority
?
383 Views
Last Modified: 2013-11-29
Software on a server consists of several processes that write errors to a single, text-based log file called “error_log.txt” – one per line. Each line of the file contains a date, time, 4-digit error code, a one-word process name, and the error message text. Spaces are placed between each part. Examples:

05/06/10 12:45:10 4242 PROCESSOR Code not found in auxiliary image
05/06/10 12:48:22 1356 HDSUBSYS Continuity check failed at interleave 33

In need to write a set of commands that will make a list of unique error codes generated by the “IOSYSGEN“ process.
0
Comment
Question by:Delta7428
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 56

Expert Comment

by:Bill Prew
ID: 39675449
Can you provide a full sample of the input file for testing?

~bp
0
 

Author Comment

by:Delta7428
ID: 39675484
I generated the attached sample file by copying and pasting a few lines and replacing the process with "IOSYGEN"

The question was submitted to me as-is from a prospective employer as part of my application process.  Albeit, the employer is most interested in my SQL skills (thank goodness), I will be learning and dabbling in DOS and Linux.
0
 
LVL 56

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 39675521
Well, here's an approach. I would encourage you to understand each line before you submit it, and even then, this feels a bit like plagiarism. Let your conscience be your guide...

@echo off
setlocal EnableDelayedExpansion

REM Define input and output files, as well as the process to report on
set InFile=in.txt
set OutFile=out.txt
set Process=IOSYSGEN

REM Clear last seen error code
set LastCode=0000

REM Capture output to report file
(
  REM Extract all lines with out process code on them, and then sort byu the error number
  for /f "tokens=3" %%A in ('find /i " %Process% " ^< "%InFile%" ^| sort /+19') do (
    REM Only report each error code once, the first time it's seen
    if "%%A" NEQ "!LastCode!" (
      echo %%A
      set LastCode=%%A
    )
  )
) > "%OutFile%"

Open in new window

~bp
0
 

Author Comment

by:Delta7428
ID: 39677535
Thanks bill.  I do understand all the lines.  The employer is aware that I have little to no proficiency in Dos and this part of the test will be based on researching and learning.  I will credit this post in my solution.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question