Splitting a .txt file into a new .txt file newbie question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Aherne746
Posts: 2
Joined: 09 Feb 2017 16:21

Splitting a .txt file into a new .txt file newbie question

#1 Post by Aherne746 » 09 Feb 2017 16:42

Hi guys, I am very new to batch codes and am self taught. I'm currently splitting a very large unique .txt file. I am outputting each unique type of data using the subsection code that is embedded into every line. I am currently using something along these lines to split each line into it's correct output .txt file.

Find string /r "^...."D currrent.txt >NAVAID.txt

From what I know this is searching for any string containing the 5th character "D" and outputting the whole line to a new .txt file called NAVAID.txt.

This is exactly what I need it to do. However, I have now run into a problem that I also need to put a similar line into another text file that looks for the 5th character to be D and the 6th B. They need to be seperate .txt files but every time I run the query it is seperacting the DB into its own file, but then selecting all the lines of text that start with D as a fifth character (including DB).

Find string /r "^...."D currrent.txt >NAVAID.txt
Find string /r "^...."DB currrent.txt >NAVAID.txt

How can I make it so that the line that references "D" will not include "DB"?

I hope that makes sense.

Thank you

dbenham
Expert
Posts: 2018
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Splitting a .txt file into a new .txt file newbie question

#2 Post by dbenham » 09 Feb 2017 17:20

You cannot be using

Code: Select all

Find string /r "^...."D currrent.txt >NAVAID.txt

You must mean

Code: Select all

findstr /r "^...."D currrent.txt >NAVAID.txt


Assuming every D line has another character after it, then you could use something like the following:

Code: Select all

findstr /r "^....D[^B]" current.txt >NAVAID.txt
findstr /r "^....DB" current.txt >NAVAIDB.txt

If you have some D lines that don't have a 6th character, then

Code: Select all

findstr /r "^....D[^B] ^....D$" current.txt >NAVAID.txt
findstr /r "^....DB" current.txt >NAVAIDB.txt


Note - Please put code within code blocks. You can use the handy Code edit button at the top of the editor. The text should look like the following before you post:

[code]
Your code goes here
[/code]


Dave Benham

Aherne746
Posts: 2
Joined: 09 Feb 2017 16:21

Re: Splitting a .txt file into a new .txt file newbie question

#3 Post by Aherne746 » 10 Feb 2017 00:42

That is awesome, thank you. And I will make sure to put my code in blocks. I will try to run it today.

Thank you

Post Reply