How to Filter a Number from a String

October 2, 2010 at 14:53:16
Specs: Windows 7
hi, everybody, I have a Big Problem.
I have a String "COM6:" in a File COM.txt, First I want to filter the Number 6 from the String.

And I have another File PORT.txt,

I want to take the place of "N" with the "6" ,that be filtered from COM.txt. N can be any number from 0 to 99.

Finally I want to make the content of the PORT.txt to be

How can I did it?
Thank you very much.

See More: How to Filter a Number from a String

Report •

October 2, 2010 at 20:01:19
download gawk for windows then do this

C:\test>gawk -F"=" "FNR==NR&&/COM/{gsub(/.*COM|:.*/,\"\");n=$0;next}/comm_ports/{$2=n}1" OFS="=" COM.txt PORT.txt

GNU win32 packages | Gawk

Report •

October 4, 2010 at 01:09:38
thank you ghostdog for your help.
But is there any other Method to do the same things, but not install a new software?
Only with the Batch? Thank you!

Report •

October 4, 2010 at 01:44:21
you only download it ONCE. Its just one .exe file. you can bring anywhere with windows machine to use. No need to download again.

GNU win32 packages | Gawk

Report •

Related Solutions

October 5, 2010 at 05:40:37
sure, i belive you.
But problem is that I really want to solve the Problem just with Batch, and not install a new software.

Report •

October 6, 2010 at 17:09:23
Hi William

I have a solution in Batch but it would only work if you change the N to something else thats not in the strings.


ie above would also change "n" in "net_ports"
you could use "No" or anything thats not in the strings

Say the number was 6, you would get this


Report •

Ask Question