Question

I'm looking for a quick way to look up the information of a line of data from a CSV (or it can be saved in any format). User needs to be prompted to enter the exact Name and the return would be additional details. Example table below.

Name | Mfr | Model | Number | Asset | Location | Unit | Install

AOM69-WC-2d HP  PROLIANT DL360 G7   USEX13S5NW  90901X3 F99 85  X2547d5

Roswell-Con-21x HP  PROLIANT DL360P GEN8    USE2O35QP0  8223173 X22 63  V2355863

My thought:

Enter the Name you are looking for:> AOM69-WC-2d

returns the data below:

AOM69-WC-2d has the following information: HP   PROLIANT DL360 G7   USEX13S5NW  90901X3 F99 85  X2547d5
Was it helpful?

Solution

The Windows command shell is not a Turing complete programming language, you will find it difficult to do anything very sophisticated without coding helper commands in some other language - in which case you might as well use another language - or using third-party utilities to perform some tasks.

The shortcomings of Windows batch files are largely addressed by Windows PowerShell, but for this application neither are probably the best choice.

You can however almost do what you want as follows:

@echo off
set /p name=Enter the name you are looking for:>
findstr /c:"%name%" datafile.csv

To get the precise output you suggested would need to perform some string processing on the findstr output, and there is no support for that in Win32. You could pipe the output of findstr to something like sed, a Windows version of which can be found here. PowerShell however supports string handling directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top