Help with batch to extract lines from .txt

February 6, 2015 at 18:48:25
Specs: Windows XP Service Pack 3
Hi,
I have a giant .txt file I need to remove some lines from. The document is a list of aeronautical waypoints around the world, and I use it for plotting in a mapping application in my air traffic control simulator game. Every month, I download the newest file, but I always need to take out several hundred lines that refer to runways/approach points, as they clutter the results when I am searching for en route waypoints.
I have been looking for a faster and easier solution than manually doing this every month, and some searching has led me to find that I need to write a .bat file.
I am not a programmer, I am a student pilot/aviation geek, and I don't have the mental agility or free time to learn a whole language and rules for this one project, so I was hoping someone here has the know-how to assist me.

Please don't think I'm just lazy, I would love to know how to do this stuff, but I figure there are a few experts on here that would be able to do this in a flash...

The text file I am using contains lines like these, and I need to completely remove the lines that refer to runways (RWY) and approach points (APP):

KATAN,KATAN,08052699N,124522720E,RPHI
KATANNING,YKNG,33420108S,117391188E,YMMM,JAR (HL),JAL (L),63 (QNH)
KATANNING RWY25 CENTRE INIT APP,KNGEB,33352776S,117562794E,YMMM,JAR (HL),JAL (L)
KEMPSEY RWY22 MISSED APP HOLD,KMPNH,31095650S,152501594E,YBBB,MNN (HL),NAA (HL),MAL A (L),MAL B (L)
KENDARI,KDI,04043229S,122271075E,WAAF
KENDARI,NI,04051137S,122244093E,WAAF
KENDL,KENDL,30451914S,134063672E,YMMM,FOR (HL),OLY (L)
KENDO,KENDO,03165027S,122274996E,WAAF
KERANG RWY14 FINAL APP,KERNF,35412637S,143533113E,YMMM,MUN (HL),MLE C (L)

What I'd like to end up with is a new file that has none of the irrelevant lines.
Or, more preferable is if the result of the batch created two new .txt files, one without the lines that I need to remove, and the other with only the removed lines, so that I can review it for anything that was missed. But only if it isn't too difficult.

I cannot install any third party software, as this is on my old XP pc, and needs to use native Windows capabilities.
Please let me know if you can help, or if there is some sort of crash course that would quickly enable me to get this one project accomplished.
If there is anything I can provide you with in return, feel free to ask.
Cheers,
Ben


See More: Help with batch to extract lines from .txt

Report •


#1
February 6, 2015 at 22:50:55
::====== script starts here ===============
::
:: benica.bat 2015-02-07 13:41:35.17
@echo off & setLocal enableDELAYedeXpansioN

find "RWY" < myfile > STRIPPED.TXT
find "APP" < myfile >> STRIPPED.TXT
find /v "APP" < myfile | find /v "RWY" > NEW.TXT
goto :eof
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#2
February 7, 2015 at 02:48:36
:: This is the WORLD FAMOUS BENICA2.BAT
:: The earlier one didn't remove duplicates from STRIPPED.TXT
::
::====== script starts here ===============
:: strips lines containing APP or RWY
:: benica2.bat 2015-02-07 17:30:34.85
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

find "RWY" < myfile > STRIPPED.TXT
find "APP" < myfile >> STRIPPED.TXT
find /v "APP" < myfile | find /v "RWY" > NEW.TXT

for /f "tokens=* delims= " %%a in (STRIPPED.TXT) do (
find "%%a" < NEWFILE > nul || >> NEWFILE echo.%%a
)
sort NEWFILE > STRIPPED.TXT & del NEWFILE
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#3
February 7, 2015 at 02:55:07
Thank you so much for your speedy response, I didn't realize it would be such a short bunch of commands!

If I wanted to remove several items, how would I write the find command?
This worked for me with "find /v":

find /v " RWY" < input.txt | find /v "ADELAIDE,IAD" | find /v "ALICE SPRINGS,IAS" > output.txt

but when I tried just "find" the resulting txt file is empty:

find " RWY" < input.txt | find "ADELAIDE,IAD" | find "ALICE SPRINGS,IAS" > output.txt

Can you please explain what I am doing wrong? Is there a better way if I wish to remove lines containing 50 or so variables?

Regards,
Ben

message edited by beninca


Report •

Related Solutions


Ask Question