<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Linux Forum &mdash; SED замена символов в определенной части текста]]></title>
	<link rel="self" href="https://linuxforum.ru/extern.php?action=feed&amp;tid=10554&amp;type=atom" />
	<updated>2011-02-01T14:49:10Z</updated>
	<generator>PunBB</generator>
	<id>https://linuxforum.ru/viewtopic.php?id=10554</id>
		<entry>
			<title type="html"><![CDATA[Re: SED замена символов в определенной части текста]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=139467#p139467" />
			<content type="html"><![CDATA[<p>Спасибо за ответ. Сейчас вижу, что не совсем корректно описал строку, с которой производятся манипуляции. На самом деле она седержит не один &quot;/&quot;, а несколько.</p><div class="codebox"><pre><code>some text with spaces/some more text with spaces/more and more text with spaces/another_text_with_spaces_which_must_be_replaced</code></pre></div><p>И замену мы делаем в определенной части, как правило последней.</p><p>Ваш пример я вижу так:<br />h;s~/.*~~;x;s~[^/]*/~~; - записать в hold space все символы до первого /<br />s/ /_/g; - в оставшемся заменить все пробелы на подчеркивания<br />H;g;s~\n~/~ - добавить к содержимому hold space измененную часть</p><p>Поправьте, если я не прав.<br />Непонятно обилие знаков ~, для чего он нужен?</p>]]></content>
			<author>
				<name><![CDATA[andro_id]]></name>
				<uri>https://linuxforum.ru/profile.php?id=15120</uri>
			</author>
			<updated>2011-02-01T14:49:10Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=139467#p139467</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: SED замена символов в определенной части текста]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=139422#p139422" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>andro_id пишет:</cite><blockquote><p>sed &#039;s/\ /_/g&#039; - заменяем пробелы на подчеркивания</p></blockquote></div><p>заменяет комбинацию кривозаписаный пробел на подчёркивание. без g заменяет только первый, с g заменяет все. Обратный слеш тут лишний. Пробельные символы записываются в sed так: <strong>\s</strong>.</p>]]></content>
			<author>
				<name><![CDATA[drBatty]]></name>
				<uri>https://linuxforum.ru/profile.php?id=86</uri>
			</author>
			<updated>2011-02-01T12:36:00Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=139422#p139422</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: SED замена символов в определенной части текста]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=139418#p139418" />
			<content type="html"><![CDATA[<p><div class="termtitle" style="font-family: sans-serif; position:relative; height:auto; width:auto; background:#3A4061; color:#FFFFFF; padding: 1px;"><b> Консоль:</b></div>
<div class="termcont" style="font-family: Terminus; position:relative; height:auto; width:auto; overflow-x:scroll; white-space: nowrap ; overflow-y:auto;background:#000000; color:#4EF44E; line-height:1.2; padding: 3px; font-size: 1rem; max-height: 60vh">$ sed &#039;h;s~/.*~~;x;s~[^/]*/~~;s/ /_/g;H;g;s~\n~/~&#039; 11.txt <br />some text with spaces/another_text_with_spaces_which_must_be_replaced<br />more some text with spaces/more_another_text_with_spaces_which_must_be_replaced<br /></div></p><p>делал так-же как вы, используя Hold Space для хранения первой части строки.</p>]]></content>
			<author>
				<name><![CDATA[drBatty]]></name>
				<uri>https://linuxforum.ru/profile.php?id=86</uri>
			</author>
			<updated>2011-02-01T12:32:43Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=139418#p139418</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[SED замена символов в определенной части текста]]></title>
			<link rel="alternate" href="https://linuxforum.ru/viewtopic.php?pid=139398#p139398" />
			<content type="html"><![CDATA[<p>Доброго времени суток.</p><p>Есть задачка, заменить пробелы на &quot;_&quot; в файле, но не во всем тексте, а определенных участках.<br />Пример:</p><div class="codebox"><pre><code>some text with spaces/another text with spaces which must be replaced
more some text with spaces/more another text with spaces which must be replaced</code></pre></div><p>нужно заменить на:<br /></p><div class="codebox"><pre><code>some text with spaces/another_text_with_spaces_which_must_be_replaced
more some text with spaces/more_another_text_with_spaces_which_must_be_replaced</code></pre></div><p>Пытаюсь так:</p><div class="codebox"><pre><code>cat testfile | cut -d / -f2 | sed &#039;s/\ /_/g&#039;</code></pre></div><p>testfile - файл, который содержит эти строки<br />cut -d / -f2 - делим текст с пом разделителя &quot;/&quot; на 2 части и берем 2-ю<br />sed &#039;s/\ /_/g&#039; - заменяем пробелы на подчеркивания<br />Но тогда замена происходит во всем тексте. Если убрать &quot;g&quot;, то замена вообще не происходит.<br />Может кто подскажет, как произвести замену только во 2-й половинке?</p>]]></content>
			<author>
				<name><![CDATA[andro_id]]></name>
				<uri>https://linuxforum.ru/profile.php?id=15120</uri>
			</author>
			<updated>2011-02-01T11:27:47Z</updated>
			<id>https://linuxforum.ru/viewtopic.php?pid=139398#p139398</id>
		</entry>
</feed>
