<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Linux Forum &mdash; Работа с текстом.]]></title>
		<link>https://linuxforum.ru/viewtopic.php?id=26782</link>
		<atom:link href="https://linuxforum.ru/extern.php?action=feed&amp;tid=26782&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «Работа с текстом.».]]></description>
		<lastBuildDate>Tue, 19 Feb 2013 20:39:56 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Работа с текстом.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=328457#p328457</link>
			<description><![CDATA[<div class="codebox"><pre><code>cat -n file.txt &gt; new.txt</code></pre></div><div class="quotebox"><blockquote><p>Да, у меня Ubuntu.<br />Нет, не глючит.</p></blockquote></div><p> <img src="https://linuxforum.ru/img/smilies/ag.gif" alt="ag" /></p>]]></description>
			<author><![CDATA[null@example.com (semiono)]]></author>
			<pubDate>Tue, 19 Feb 2013 20:39:56 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=328457#p328457</guid>
		</item>
		<item>
			<title><![CDATA[Re: Работа с текстом.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=328287#p328287</link>
			<description><![CDATA[<div class="codebox"><pre><code>#!/usr/bin/env python
#-*- coding: utf-8 -*-

import sys

if len(sys.argv) != 2:
    sys.stderr.write(&quot;Usage: %s &lt;file&gt;\n&quot; % sys.argv[0])
    raise SystemExit(1)
fname = sys.argv[1]
with open(fname, &#039;r&#039;) as f:
    lines = f.readlines()
n = 0
with open(fname, &#039;w&#039;) as f:
    for line in lines:
        n += 1
        f.write(str(n) + &#039;\t&#039; + line)</code></pre></div><p>Правда, с форматированием лучше бы.<br />Можно собрать бинарник хоть под Linux, хоть под Windows:)</p><p>Ну, или man sed.</p>]]></description>
			<author><![CDATA[null@example.com (-=Serj=-)]]></author>
			<pubDate>Tue, 19 Feb 2013 08:51:45 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=328287#p328287</guid>
		</item>
		<item>
			<title><![CDATA[Re: Работа с текстом.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=328281#p328281</link>
			<description><![CDATA[<div class="quotebox"><cite>semiono пишет:</cite><blockquote><p>Не совсем сформулировал задачу, нужно в готовый текст в начало строк нумерация, но наверное это сложнее</p></blockquote></div><p>нет, не сложно, вот на примере готового файла hosts.allow<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><p>root@monitoring:/etc# cat hosts.allow<br /># /etc/hosts.allow: list of hosts that are allowed to access the system.<br />#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;See the manual pages hosts_access(5) and hosts_options(5).<br />#<br /># Example:&nbsp; &nbsp; ALL: LOCAL @some_netgroup<br />#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ALL: .foobar.edu EXCEPT terminalserver.foobar.edu<br />#<br /># If you&#039;re going to protect the portmapper use the name &quot;portmap&quot; for the<br /># daemon name. Remember that you can only use the keyword &quot;ALL&quot; and IP<br /># addresses (NOT host or domain names) for the portmapper, as well as for<br /># rpc.mountd (the NFS mount daemon). See portmap(8) and rpc.mountd(8)<br /># for further information.</p><p>теперь номеруем строчки</p><p>root@monitoring:/etc# cat hosts.allow | cat -n<br />&nbsp; &nbsp; &nbsp;1&nbsp; # /etc/hosts.allow: list of hosts that are allowed to access the system.<br />&nbsp; &nbsp; &nbsp;2&nbsp; #&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;See the manual pages hosts_access(5) and hosts_options(5).<br />&nbsp; &nbsp; &nbsp;3&nbsp; #<br />&nbsp; &nbsp; &nbsp;4&nbsp; # Example:&nbsp; &nbsp; ALL: LOCAL @some_netgroup<br />&nbsp; &nbsp; &nbsp;5&nbsp; #&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ALL: .foobar.edu EXCEPT terminalserver.foobar.edu<br />&nbsp; &nbsp; &nbsp;6&nbsp; #<br />&nbsp; &nbsp; &nbsp;7&nbsp; # If you&#039;re going to protect the portmapper use the name &quot;portmap&quot; for the<br />&nbsp; &nbsp; &nbsp;8&nbsp; # daemon name. Remember that you can only use the keyword &quot;ALL&quot; and IP<br />&nbsp; &nbsp; &nbsp;9&nbsp; # addresses (NOT host or domain names) for the portmapper, as well as for<br />&nbsp; &nbsp; 10&nbsp; # rpc.mountd (the NFS mount daemon). See portmap(8) and rpc.mountd(8)<br />&nbsp; &nbsp; 11&nbsp; # for further information.</p><p>как видно, все пронумеровалось. но есть и второй способ. открой любой vi-подобный редактор. Например vim и напиши : set number. результат тот же самый увидешь. пример</p><p>&nbsp; 1 # /etc/hosts.allow: list of hosts that are allowed to access the system.<br />&nbsp; 2 #&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;See the manual pages hosts_access(5) and hosts_options(5).<br />&nbsp; 3 #<br />&nbsp; 4 # Example:&nbsp; &nbsp; ALL: LOCAL @some_netgroup<br />&nbsp; 5 #&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ALL: .foobar.edu EXCEPT terminalserver.foobar.edu<br />&nbsp; 6 #<br />&nbsp; 7 # If you&#039;re going to protect the portmapper use the name &quot;portmap&quot; for the<br />&nbsp; 8 # daemon name. Remember that you can only use the keyword &quot;ALL&quot; and IP<br />&nbsp; 9 # addresses (NOT host or domain names) for the portmapper, as well as for<br /> 10 # rpc.mountd (the NFS mount daemon). See portmap(8) and rpc.mountd(8)<br /> 11 # for further information.<br /> 12 #<br /> 13<br />~<br />~<br />~<br />~<br />~<br />:set number</p></div></div>]]></description>
			<author><![CDATA[null@example.com (Linux777)]]></author>
			<pubDate>Tue, 19 Feb 2013 08:43:51 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=328281#p328281</guid>
		</item>
		<item>
			<title><![CDATA[Re: Работа с текстом.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=328277#p328277</link>
			<description><![CDATA[<p>Не совсем сформулировал задачу, нужно в готовый текст в начало строк нумерация, но наверное это сложнее</p>]]></description>
			<author><![CDATA[null@example.com (semiono)]]></author>
			<pubDate>Tue, 19 Feb 2013 08:23:32 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=328277#p328277</guid>
		</item>
		<item>
			<title><![CDATA[Re: Работа с текстом.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=328223#p328223</link>
			<description><![CDATA[<p>Ответ есть в man cat.</p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>$ echo -e &quot;line\nline\nline&quot; | cat -n
     1    line
     2    line
     3    line</code></pre></div></div></div>]]></description>
			<author><![CDATA[null@example.com (bormant)]]></author>
			<pubDate>Tue, 19 Feb 2013 03:39:19 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=328223#p328223</guid>
		</item>
		<item>
			<title><![CDATA[Re: Работа с текстом.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=328211#p328211</link>
			<description><![CDATA[<p><strong>nl</strong> входит в coreutils, так что быть должен...<br />для grep&#039;а ключ -n смотри.<br />для sed&#039;а через = можно, но не очень красиво получается...</p>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Tue, 19 Feb 2013 00:19:11 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=328211#p328211</guid>
		</item>
		<item>
			<title><![CDATA[Работа с текстом.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=328210#p328210</link>
			<description><![CDATA[<p>Как пронумеровать строки в файле?<br />grep, sed, regex ?<br />Только по-проще покажите, потому что нужно для GnuWin32 под виндоус <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /><br />sed, например, там без &#039;кавычек&#039; работает: sed -i s/string1/string2/g file<br />Впрочем под linux тоже интересно.</p>]]></description>
			<author><![CDATA[null@example.com (semiono)]]></author>
			<pubDate>Mon, 18 Feb 2013 23:55:57 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=328210#p328210</guid>
		</item>
	</channel>
</rss>
