Page 1 of 1

filter out / replace text string with blank text in text doc

Posted: 28 Mar 2010 00:14
by jamesfui
Hi Dostips Batch Scripters,

the bat will filter out / Replace All Specific text string as reference from a text doc (ref.txt) with Blank text into the list in (needfilter.txt) BUT will not Erase the Whole Line together in Series with it..

for example "filter out this text string" but keep this text in series with it.
Result: but keep this text in series with it.

i used notepad successfully replace it but for many Different & LONG text strings need to be filter out in a long list, it is quite time consuming... :(

So if possible the bat will get the Reference text string from (ref.txt) and
replace all relevant text string in (needfilter.txt) WITHOUT erase its text in series with it..

Do anyone know how to solve script like above??
Thanks. :D

Re: filter out / replace text string with blank text in text

Posted: 28 Mar 2010 08:07
by aGerman
Could work, but imho not a good idea to make a batch script for those intentions. You have to ascape all signs like ^, &, <, >, | and it will take a long time, because it would work like that:
- for each line in ref.txt call a subroutine
- for each line in needfilter.txt replace all special characters one by one
- after that replace the search-string
- write it to another file
- replace the old file with the new file and start again until all lines of ref.txt are processed

Better you would use a scripting language like VBScript or something else.

Regards
aGerman

Re: filter out / replace text string with blank text in text

Posted: 28 Mar 2010 18:47
by ghostmachine4
jamesfui wrote:Hi Dostips Batch Scripters,

the bat will filter out / Replace All Specific text string as reference from a text doc (ref.txt) with Blank text into the list in (needfilter.txt) BUT will not Erase the Whole Line together in Series with it..

for example "filter out this text string" but keep this text in series with it.
Result: but keep this text in series with it.

i used notepad successfully replace it but for many Different & LONG text strings need to be filter out in a long list, it is quite time consuming... :(

So if possible the bat will get the Reference text string from (ref.txt) and
replace all relevant text string in (needfilter.txt) WITHOUT erase its text in series with it..

Do anyone know how to solve script like above??
Thanks. :D



download gawk for windows at: gnuwin32.sourceforge.net/packages/gawk.htm
and use this one liner

Code: Select all


C:\test>more file
filter out this text string but keep this text in series with it.

C:\test>more ref.txt
filter out this text string

C:\test>gawk "FNR==NR{a[$0];next}{for(i in a)gsub(i,\"\")}1" ref.txt file
 but keep this text in series with it.

Re: filter out / replace text string with blank text in text

Posted: 29 Mar 2010 04:56
by jamesfui
thanks for the gawk info. will try it out asap..! :wink:
.
.
But hopefully batch could also accomplish this kind of process too;
i will give more details on this..

for example in a (needfilter.txt)
c:\reports\january\submitted\report_jan10.xls
c:\reports\february\not submitted\report_feb10.xls
c:\...etc

need to filter out / replace the "c:\reports\january\submitted\" with Empty text
so it will just gives back only the filename: report_jan10.xls

another text document will be the (ref.txt) where it lists out all the text strings that need to be filter out:
"c:\reports\january\submitted\"
"c:\reports\february\not submitted\"
"c:\...etc..\"

it will took quite a long time if there is many Different Path to filter them all out one by one using the notepad built in replace feature..

So, is it possible to just keep the filename with extension only without the full path of it.? thanks :?