Solved

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

Posted on 2013-11-25
5
364 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
  • 2
  • 2
5 Comments
 
LVL 51

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 51

Accepted Solution

by:
Bill Prew earned 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now