Solved

Batch file find words in text file

Posted on 2016-09-22
2
24 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 24

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Learn about cloud computing and its benefits for small business owners.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

770 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