Solved

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

Posted on 2013-11-25
5
367 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 52

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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

9 Experts available now in Live!

Get 1:1 Help Now