Replacing variable text patterns

March 12, 2009 at 23:33:29
Specs: Windows 7/XP/Server 2008/Ubuntu
I have a large ip list with port number appended to the end of each file like:
10.0.0.1:100
10.0.0.1:39529
192.168.10.1:80

etc etc

I've been trying to figure out a way to automatically remove everything between and including each ":" and "return".

I'd like to do this in cmd.exe, but I wouldn't mind using shell in linux. Any help would be greatly appreciated.


See More: Replacing variable text patterns

Report •


#1
March 13, 2009 at 00:09:46
Do you mean something like:

for /f "usebackq tokens=1 delims=:" %%a in ("your text file.txt") do echo %%a


Report •

#2
March 13, 2009 at 00:39:18
I tried a couple variations of your suggestion from the comm@nd line and it this is what it looks like:

C:\Windows\system32>for /f "usebackq tokens=1 delims=:" %%a in ("c:\users\docume
nts\test.txt") do echo %%a
%%a was unexpected at this time.

I've been s3arching off and on for days without finding the right inf0rm@tion. I'm missing something...


Report •

#3
March 13, 2009 at 01:08:07
@echo off > newfile & setLocal EnableDelayedExpansion

for /f "tokens=1 delims=:" %%a in (iplist) do (
echo %%a >> newfile
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
March 13, 2009 at 01:29:35
%%a was unexpected at this time.

HDJunkie, when you type the for loop directly into command prompt, you use single percent (%) instead of double percent.

if the for loop is inside a batch file, then you use double percent (%%)


Report •

#5
March 13, 2009 at 01:39:08
Wow, it works!

Thanks so much for the help guys. I should of come here days ago instead of searching aimlessly.

I wish I understood why it works. Does anyone have any suggested reading/sites to learn?

Additionally, would it be possible to add a command to remove an entire line if it contains brackets? "[]"


Report •

#6
March 13, 2009 at 01:47:39
Go to the command line and type in "for /?" or type in "help" to see available commands.

Report •

#7
March 13, 2009 at 05:22:34
"Additionally, would it be possible to add a command to remove an entire line if it contains brackets? "[]""

find /v "[" < myfile | find /v "]" > newfile


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question