Articles

Solved How to use regular expression to bulk edit text files?

December 11, 2012 at 21:41:31
Specs: Windows 7

Hi,

I'm reading http://cybernetnews.com/find-replac... how to bulk find and replace words. He is using notepad ++.


So, is there is any method to bulk find urls within the text files and remove the urls using notepad ++.

The urls I want to remove is anything begin with http:// or www. or anything ending with .com .org .net

Thanks. I really appreciate your help.

Regards,
Jerry


See More: How to use regular expression to bulk edit text files?

Report •


✔ Best Answer
December 16, 2012 at 02:37:20

This gets out http:// and .net; you can guess the rest.

:: =====  script starts here  ===============
:: cut out http:// www .com etc
:: jerry.bat  2012-12-16 15:00:39.42
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in (myfile) do (
call :sub1 %%a
echo !S!
) >> newfile
goto :eof

:sub1
set S=
:loop
echo %1 | find "http://" > nul || echo %1 | find ".net" > nul ||  set S=!S! %1
  if "%2" neq "" (
    shift
    goto :loop
  )
goto :eof
::======  script ends here  =================

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



#1
December 11, 2012 at 22:13:26

I don't see where notepad++ supports regexp, but I could be wrong. Vbscript, i think, has access to regexp, and probably applies it correctly. I would recommend this route, although I am not good with reg.exp. Also, if you could post sample of a file's content, that might help with further progress from forum contributors.

Report •

#2
December 11, 2012 at 22:22:15

According to this http://cybernetnews.com/find-replac... . Is there is any method using notepad ++ to find and remove anything begin with http:// or www. or anything ending with .com .org .net from .txt files. I have few hundreds .txt need to bulk edit. Thanks.

Report •

#3
December 13, 2012 at 19:27:36

Yes, you're right (I downloaded np++). Reg.exp IS supported. I haven't tried to test it yet. I guess "bulk edit" stipulation might be met by the macro menu. Sorry for the "non-answer", but I just wanted to let you know you're right and I'm wrong! ;-)
Maybe I'll get time to work with it (learning curve is always more like a tidal wave for me, not to mention me being sucky at reg.exp in general, and by now you've prob'ly got an answer anyhoos.).
Ps: As M2 indicated, some sample target-file content would help.

Report •

Related Solutions

#4
December 14, 2012 at 01:22:57

Might get done with a script, but not until we see some lines of the files.

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


Report •

#5
December 15, 2012 at 11:24:04

A quick Google search turned up this regular expression for URLs as the first hit. I haven't tested it, so use at your own risk, and whatnot.

How To Ask Questions The Smart Way


Report •

#6
December 16, 2012 at 02:37:20
✔ Best Answer

This gets out http:// and .net; you can guess the rest.

:: =====  script starts here  ===============
:: cut out http:// www .com etc
:: jerry.bat  2012-12-16 15:00:39.42
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in (myfile) do (
call :sub1 %%a
echo !S!
) >> newfile
goto :eof

:sub1
set S=
:loop
echo %1 | find "http://" > nul || echo %1 | find ".net" > nul ||  set S=!S! %1
  if "%2" neq "" (
    shift
    goto :loop
  )
goto :eof
::======  script ends here  =================

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


Report •

#7
December 16, 2012 at 02:43:52

Thanks guys for your help! Appreciate that :) SOLVED now!

Regards,
Jerry


Report •


Ask Question