<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Linux Forum &mdash; Работа с текстом.]]></title>
	<link rel="self" href="https://linuxforum.ru/extern.php?action=feed&amp;tid=26782&amp;type=atom" />
	<updated>2013-02-19T20:39:56Z</updated>
	<generator>PunBB</generator>
	<id>https://linuxforum.ru/viewtopic.php?id=26782</id>
		<entry>
			<title type="html"><![CDATA[Re: Работа с текстом.]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=328457#p328457" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[semiono]]></name>
				<uri>https://linuxforum.ru/profile.php?id=27919</uri>
			</author>
			<updated>2013-02-19T20:39:56Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=328457#p328457</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Работа с текстом.]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=328287#p328287" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[-=Serj=-]]></name>
				<uri>https://linuxforum.ru/profile.php?id=16175</uri>
			</author>
			<updated>2013-02-19T08:51:45Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=328287#p328287</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Работа с текстом.]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=328281#p328281" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Linux777]]></name>
				<uri>https://linuxforum.ru/profile.php?id=23921</uri>
			</author>
			<updated>2013-02-19T08:43:51Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=328281#p328281</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Работа с текстом.]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=328277#p328277" />
			<content type="html"><![CDATA[<p>Не совсем сформулировал задачу, нужно в готовый текст в начало строк нумерация, но наверное это сложнее</p>]]></content>
			<author>
				<name><![CDATA[semiono]]></name>
				<uri>https://linuxforum.ru/profile.php?id=27919</uri>
			</author>
			<updated>2013-02-19T08:23:32Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=328277#p328277</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Работа с текстом.]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=328223#p328223" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[bormant]]></name>
				<uri>https://linuxforum.ru/profile.php?id=732</uri>
			</author>
			<updated>2013-02-19T03:39:19Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=328223#p328223</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Работа с текстом.]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=328211#p328211" />
			<content type="html"><![CDATA[<p><strong>nl</strong> входит в coreutils, так что быть должен...<br />для grep&#039;а ключ -n смотри.<br />для sed&#039;а через = можно, но не очень красиво получается...</p>]]></content>
			<author>
				<name><![CDATA[Fat-Zer]]></name>
				<uri>https://linuxforum.ru/profile.php?id=11911</uri>
			</author>
			<updated>2013-02-19T00:19:11Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=328211#p328211</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Работа с текстом.]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=328210#p328210" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[semiono]]></name>
				<uri>https://linuxforum.ru/profile.php?id=27919</uri>
			</author>
			<updated>2013-02-18T23:55:57Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=328210#p328210</id>
		</entry>
</feed>
