<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: findstr и кодировка 1251]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7578&amp;type=atom" />
	<updated>2012-12-11T18:10:36Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=7578</id>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66881#p66881" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>smaharbA пишет:</cite><blockquote><p>echo off<br />chcp 1251 &gt; nul<br />chcp 866 &gt; nul&amp;echo строка в сп1251|findstr /c:&quot;строка в сп&quot;</p></blockquote></div><p>И где здесь поиск по входным файлам?</p>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2012-12-11T18:10:36Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66881#p66881</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66877#p66877" />
			<content type="html"><![CDATA[<p>echo off<br />chcp 1251 &gt; nul<br />chcp 866 &gt; nul&amp;echo строка в сп1251|findstr /c:&quot;строка в сп&quot;</p>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2012-12-11T17:50:33Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66877#p66877</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66876#p66876" />
			<content type="html"><![CDATA[<p>Нужен универсальный способ вызова <strong>findstr </strong>для обработки текстовых файлов в кодировке 1251.<br />Без предварительной перекодировки входных файлов.</p><p>Я уточняю условия&nbsp; (это только один из случаев, просто для примера):<br />Допустим есть пара тысяч html-файлов - нужно среди них найти все файлы в которых содержится определенная строка (состоящая из кириллицы), чтобы скопировать эти файлы в другой каталог </p><p>Если строка не содержит кириллицу, то делаем так </p><div class="codebox"><pre><code>for /F %A in (&#039;findstr /M &quot;строка&quot; *.html&#039;) do @xcopy %A  C:\backup </code></pre></div><p>Задача заменить <strong>findstr </strong> на любой bat/cmd-file или даже VBS, но только бы заставить этот <strong>findstr </strong>искать строки в файлах с кодировкой 1251. Способ простой перекодировки вводимой строки из 1251 в 866 не срабатывает, поскольку этот чертов findstr некоторые перекодированные символы не понимает.&nbsp; Например ю и П.<br />Единственный, на мой взгляд способ, (хотя и не очень корректный) это сделать собственную таблицу перекодировки, win2dos, и те символы, которые findstr не понимает, заменять на точку.</p>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2012-12-11T17:44:21Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66876#p66876</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66872#p66872" />
			<content type="html"><![CDATA[<p>echo off<br />chcp 1251 &gt; nul<br />chcp 866 &gt; nul&amp;echo строка в сп1251|findstr &quot;строка&quot;</p>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2012-12-11T17:16:18Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66872#p66872</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66721#p66721" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>@Echo off

:: Поиск кириллической строки с помощью findstr.
:: Параметры запуска: строка поиска/имя файла с путем
:: Пример: &quot;C:\Findtxt.bat&quot; что я ищу/C:\Мой текст.txt

chcp 1251 &gt;nul 2&gt;&amp;1
set str=%*%
for /f &quot;tokens=1,2* delims=/&quot; %%a in (&#039;echo.%str%&#039;) do (
set str=%%a
set file=&quot;%%~b&quot;
)

for /f &quot;tokens=*&quot; %%i in (&#039;cmd /c &quot;chcp 1251 &gt;nul &amp;&amp; echo.%str% | (chcp 866 &gt; nul &amp;&amp; find /v &quot;&quot;) | findstr /g:/ %file% | (chcp 1251 &gt;nul &amp;&amp; find /v &quot;&quot;)&quot;&#039;) do  (
chcp 866 &gt;nul 2&gt;&amp;1
echo.%%i
)
Pause &gt;nul 2&gt;&amp;1
EXIT
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Blaze812]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29212</uri>
			</author>
			<updated>2012-12-06T10:21:16Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66721#p66721</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66691#p66691" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Blaze812 пишет:</cite><blockquote><p>Медленно конечно... на файл 21847 строк ушло 4 минуты...</p></blockquote></div><p>1. искомая строка должна быть входным параметром для .bat-файла<br />2. 4 минуты для 20 тысяч строк... такая &quot;скорость&quot; никуда не годится. ;(</p>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2012-12-06T01:53:25Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66691#p66691</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66688#p66688" />
			<content type="html"><![CDATA[<p>А если так:</p><div class="codebox"><pre><code>@Echo off

chcp 1251 &gt;nul 2&gt;&amp;1
set str1=Строка или часть строки, которую ищем. 
for /f &quot;tokens=*&quot; %%i in (Имя файла с путем, на английском или в DOS кодировке.) do call :to866 &quot;%%i&quot;
del /f /q &quot;%temp%\000.txt&quot;
for /f &quot;tokens=*&quot; %%i in (%temp%\001.txt) do echo.%%~i
del /f /q &quot;%temp%\001.txt&quot;

Pause &gt;nul 2&gt;&amp;1
EXIT

:to866
chcp 866 &gt;nul 2&gt;&amp;1
&gt;&quot;%temp%\000.txt&quot; echo.%1%
&gt;&gt;&quot;%temp%\001.txt&quot; findstr /I /C:&quot;%str1%&quot; &quot;%temp%\000.txt&quot;
GoTo :EOF
</code></pre></div><p>Медленно конечно... на файл 21847 строк ушло 4 минуты...</p>]]></content>
			<author>
				<name><![CDATA[Blaze812]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29212</uri>
			</author>
			<updated>2012-12-05T22:44:45Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66688#p66688</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66665#p66665" />
			<content type="html"><![CDATA[<p><strong>Blaze812</strong> я что-то не понял при чем тут этот пример?<br />Речь шла о том, что нужно искать текстовые строки в файлах с кодировкой 1251. <br />Дополнительное условие:&nbsp; Размер входных файлов достаточно велик, чтобы их перекодировать.</p><p>Самый простой способ использовать <strong>grep</strong>, но к сожалению grep есть не на каждой машине...</p>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2012-12-05T16:52:37Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66665#p66665</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66455#p66455" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>@Echo off

chcp 1251 &gt;nul 2&gt;&amp;1
set str1=Основной шлюз
for /f &quot;tokens=*&quot; %%i in (&#039;ipconfig /all&#039;) do call :to866 &quot;%%i&quot;

Pause &gt;nul 2&gt;&amp;1
EXIT

:to866
chcp 866 &gt;nul 2&gt;&amp;1
echo.%~1 | findstr /I /C:&quot;%str1%&quot;
GoTo :EOF
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Blaze812]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29212</uri>
			</author>
			<updated>2012-12-03T13:38:13Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66455#p66455</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66318#p66318" />
			<content type="html"><![CDATA[<p>Всё просто <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" /></p><div class="codebox"><pre><code>@Echo off

chcp 1251 &gt;nul 2&gt;&amp;1
set str1=Основной шлюз
for /f &quot;tokens=*&quot; %%i in (&#039;ipconfig /all&#039;) do call :to866 &quot;%%i&quot;

Pause &gt;nul 2&gt;&amp;1
EXIT

:to866
chcp 866 &gt;nul 2&gt;&amp;1
echo.%~1 | findstr /I /C:&quot;%str1%&quot;
GoTo :EOF</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Blaze812]]></name>
			</author>
			<updated>2012-11-30T22:59:28Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66318#p66318</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=63967#p63967" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>smaharbA пишет:</cite><blockquote><div class="codebox"><pre><code>cmd /c &quot;chcp 1251 &gt;nul &amp;&amp; echo Вася | (chcp 866 &gt; nul &amp;&amp; find /v &quot;&quot;) | findstr /g:/ file.txt | (chcp 1251 &gt;nul &amp;&amp; find /v &quot;&quot;)&quot;</code></pre></div></blockquote></div><p><strong>smaharbA </strong>&nbsp; можете описать&nbsp; что делает этот код, а то тут куча конвейеров - не совсем понятно...</p>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2012-09-18T16:54:31Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=63967#p63967</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=63966#p63966" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>wisgest пишет:</cite><blockquote><p>воспользоваться для перекодировки строки временным файлом: </p><div class="codebox"><pre><code>chcp 1251&gt;nul
echo %1&gt;tmp.tmp
chcp 866&gt;nul
set /p str=&lt;tmp.tmp
findstr &quot;%str%&quot; *.html</code></pre></div></blockquote></div><p>Такая перекодировка тоже не помогает.&nbsp; Попробовал с разными входными строками&nbsp; так и не понял почему в каких-то случаях работает, в каких то нет. Видимо некоторые символы кириллицы при перекодировке у <strong>findstr </strong> вызывают помешательство. Он даже не пытается искать.... </p><p>Вывод: Сам буду использовать grep <img src="//forum.script-coding.com/img/smilies/cool.png" width="15" height="15" />, а остальным предложу конвертировать входные файлы. <img src="//forum.script-coding.com/img/smilies/hmm.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2012-09-18T16:52:50Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=63966#p63966</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=63940#p63940" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>cmd /c &quot;chcp 1251 &gt;nul &amp;&amp; echo Вася | (chcp 866 &gt; nul &amp;&amp; find /v &quot;&quot;) | findstr /g:/ file.txt | (chcp 1251 &gt;nul &amp;&amp; find /v &quot;&quot;)&quot;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2012-09-18T06:26:52Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=63940#p63940</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=63934#p63934" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>yuriy2000 пишет:</cite><blockquote><p>я же предполагал использовать вызов через передачу параметра</p></blockquote></div><p>Можно попробовать перекодировать и переменный параметр.<br />Я, правда, не уверен, что нельзя придумать что-либо получше и не проверял, как это работает со всеми буквами, но мне на ум приходят лишь два решения:<br />воспользоваться для перекодировки строки временным файлом: </p><div class="codebox"><pre><code>chcp 1251&gt;nul
echo %1&gt;tmp.tmp
chcp 866&gt;nul
set /p str=&lt;tmp.tmp
findstr &quot;%str%&quot; *.html</code></pre></div><p>или зафиксировать в самом командном файле две строки с символами в разных кодировках и потом во внешнем цикле посимвольно просматривать преобразуемую строку, во внутреннем цикле — строку с символами в одной кодировке и при нахождении совпадения заменять символом второй кодировки с тем же номером…</p><p>Может, чем-то полезна будет тема «<a href="http://forum.script-coding.com/viewtopic.php?id=876">CMD/BAT: обработка (фильтрация) текста</a>» (я в неё не вникал)?</p>]]></content>
			<author>
				<name><![CDATA[wisgest]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=3850</uri>
			</author>
			<updated>2012-09-18T02:17:06Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=63934#p63934</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: findstr и кодировка 1251]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=63919#p63919" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>wisgest пишет:</cite><blockquote><p>Кроме перекодировки входных файлов ещё возможна перекодировка &quot;супер-пупер-строки&quot;…</p></blockquote></div><p>да, согласен, но этот чертов <strong>findstr</strong> не все перекодированные таким образом кириллические буквы понимает.<br />Например [ю] [П] <img src="//forum.script-coding.com/img/smilies/hmm.png" width="15" height="15" /></p><p>я же предполагал использовать вызов через передачу параметра </p><div class="codebox"><pre><code>
@chcp 1251 &gt;nul
findstr &quot;%1&quot; *.html 
@chcp 866 &gt;nul</code></pre></div>]]></content>
			<author>
				<name><![CDATA[yuriy2000]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25753</uri>
			</author>
			<updated>2012-09-17T03:43:43Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=63919#p63919</id>
		</entry>
</feed>
