Solved

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

Posted on 2013-11-25
5
374 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 54

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 54

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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