Solved

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

Posted on 2013-11-25
5
370 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 53

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 53

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

12 Experts available now in Live!

Get 1:1 Help Now