Solved

Batch file find words in text file

Posted on 2016-09-22
2
25 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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