Solved

Batch file find words in text file

Posted on 2016-09-22
2
21 Views
Last Modified: 2016-11-07
Read all the record from a home inventory text file,  find the first space reading from left to right, define key or word as the string to the left of the space. Write that key to new file then sort the file and remove duplicates. The input file is a list of inventory items for a home. First word is like Bed RM1, Bed RM2, Utility Rm, Garage and etc followed by item descriptiom, cost, and age.Steve King had a solution on the code for removing dips in 5-14-2012
0
Comment
Question by:Sherwood Lemoine
2 Comments
 
LVL 23

Accepted Solution

by:
NVIT earned 500 total points
ID: 41811840
Assumes your input file named Rooms.txt which looks like:
Bed RM1, description, cost, 10
Bed RM2, description, cost, 10
Utility Rm, description, cost, and age
Garage, description, cost, and age
Storage Rm, description, cost, and age

Open in new window

Make a unique.bat file of code below.

@echo off
setlocal enabledelayedexpansion

set FNInput=Rooms.txt
set FNOut1=Output_temp.txt
if exist "%FNOut1%" del /q "%FNOut1%"
for /f "tokens=1 delims=," %%a in ('type "%FNInput%"') do (
  for /f "tokens=1" %%A in ('echo %%a') do (
    >> "%FNOut1%" echo %%A
  )
)
if exist "%FNOut1%" (
  set "prev="
  for /f "delims=" %%F in ('sort "%FNOut1%"') do (
    set "curr=%%F"
    setlocal enabledelayedexpansion
    if !prev! neq !curr! echo !curr!
    endlocal
    set "prev=%%F"
  )
)

Open in new window


Run it like so:
unique.bat>output.txt

Open in new window


Resultant output.txt:
Bed
Garage
Storage
Utility

Open in new window

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

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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