Remove/Replace NUL in file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
High_Noonan
Posts: 4
Joined: 15 Jul 2016 13:28

Remove/Replace NUL in file

#1 Post by High_Noonan » 15 Jul 2016 13:42

Hello,

I am new to batch scripting and have hit something of a show stopper for me.
I am trying to automate the capture of data from our Cisco switches and managed to get a batch script working with plink earlier today.
Very exciting stuff.
Now that I have the output saved in a file (say rawMACList.txt), I am trying to pull out only the parts of the file that I need.
I have identified these lines as being the only ones that begin with a digit, so that seems like it will be straight forward enough.
But, I am having trouble searching through the entire file. Looking at the file in Notepad++, I see a NUL character right up near the top (about 15 lines in) and all processing by my For loop stops at that point.
How can I go about removing or replacing this NUL, within my script, prior to the main processing For loop?

Oh! On this computer, I am extremely locked down, so sed and every other easy solution that requires an additional download is right out. The only reason I was able to even get plink.exe is because of puTTY.

Thanks. If you need any additional details, I will do my best to provide them.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove/Replace NUL in file

#2 Post by foxidrive » 16 Jul 2016 04:51

Try this, but your file could be unicode or anything else.

Code: Select all

findstr ^[0-9] "yourfile.txt" > "newfile.txt"

High_Noonan
Posts: 4
Joined: 15 Jul 2016 13:28

Re: Remove/Replace NUL in file

#3 Post by High_Noonan » 21 Jul 2016 08:27

I didn't really understand that at first, but it struck me this morning what you were accomplishing.
I just ran it on the file and it worked amazingly well.

Thank you! Profoundly.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Remove/Replace NUL in file

#4 Post by foxidrive » 21 Jul 2016 13:33

High_Noonan wrote:Thank you! Profoundly.


Nice to hear it works, ta.

Code: Select all

findstr ^[0-9]


This is a regular expression ^[0-9]
The ^ means to anchor the text to the start of a line, so anything in the following parts of the regular expression only triggers when it is at the very start of a line.

This means to search for any character that is within the range of zero to nine - which is all numerals obviously.
[0-9]

Check out this post viewtopic.php?p=47920#p47920 :)

Post Reply