<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic sed and replace character in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/sed-and-replace-character/m-p/4007398#M96231</link>
    <description>hi all &lt;BR /&gt;i have problem with sed command to replace space with _.&lt;BR /&gt;&lt;BR /&gt;i have file formated as follow:&lt;BR /&gt;&lt;BR /&gt;f_name = [kamal ahmed kamal] job = [sysadmin]&lt;BR /&gt;address = [30 A anything Street] ....etc&lt;BR /&gt;i want to replace only spaces between [ ].&lt;BR /&gt;so the file become:&lt;BR /&gt;&lt;BR /&gt;f_name = [kamal_ahmed_kamal] job = [sysadmin]&lt;BR /&gt;address = [30_A_anything Street] ....etc&lt;BR /&gt;&lt;BR /&gt;can any one help me ?&lt;BR /&gt;many thanks&lt;BR /&gt;&lt;BR /&gt;kamal</description>
    <pubDate>Fri, 25 May 2007 12:58:01 GMT</pubDate>
    <dc:creator>k_tohamy</dc:creator>
    <dc:date>2007-05-25T12:58:01Z</dc:date>
    <item>
      <title>sed and replace character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-and-replace-character/m-p/4007398#M96231</link>
      <description>hi all &lt;BR /&gt;i have problem with sed command to replace space with _.&lt;BR /&gt;&lt;BR /&gt;i have file formated as follow:&lt;BR /&gt;&lt;BR /&gt;f_name = [kamal ahmed kamal] job = [sysadmin]&lt;BR /&gt;address = [30 A anything Street] ....etc&lt;BR /&gt;i want to replace only spaces between [ ].&lt;BR /&gt;so the file become:&lt;BR /&gt;&lt;BR /&gt;f_name = [kamal_ahmed_kamal] job = [sysadmin]&lt;BR /&gt;address = [30_A_anything Street] ....etc&lt;BR /&gt;&lt;BR /&gt;can any one help me ?&lt;BR /&gt;many thanks&lt;BR /&gt;&lt;BR /&gt;kamal</description>
      <pubDate>Fri, 25 May 2007 12:58:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-and-replace-character/m-p/4007398#M96231</guid>
      <dc:creator>k_tohamy</dc:creator>
      <dc:date>2007-05-25T12:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: sed and replace character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-and-replace-character/m-p/4007399#M96232</link>
      <description>&lt;!--!*#--&gt;Hello kamal,&lt;BR /&gt;&lt;BR /&gt;$ cat tr_sp.pl&lt;BR /&gt;#!/usr/bin/perl -wn&lt;BR /&gt;foreach $byte (split //,$_)&lt;BR /&gt;{&lt;BR /&gt;    $byte =~ /\[/ and $br=1;&lt;BR /&gt;    $byte =~ /\]/ and $br=0;&lt;BR /&gt;    $br and $byte =~ s/ /_/;&lt;BR /&gt;    print $byte;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;$ cat recs&lt;BR /&gt;f_name = [kamal ahmed kamal] job = [sysadmin]&lt;BR /&gt;address = [30 A anything Street] ....etc&lt;BR /&gt;&lt;BR /&gt;$ perl tr_sp.pl recs&lt;BR /&gt;f_name = [kamal_ahmed_kamal] job = [sysadmin]&lt;BR /&gt;address = [30_A_anything_Street] ....etc&lt;BR /&gt;&lt;BR /&gt;PCS</description>
      <pubDate>Fri, 25 May 2007 14:27:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-and-replace-character/m-p/4007399#M96232</guid>
      <dc:creator>spex</dc:creator>
      <dc:date>2007-05-25T14:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: sed and replace character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-and-replace-character/m-p/4007400#M96233</link>
      <description>This ugly piece of perl seems to do it in one line.&lt;BR /&gt;I'm sure it can be writting better, but here it goes...&lt;BR /&gt;&lt;BR /&gt; perl -pe '1 while (s/(\[\S*?)\s([^\[]+\])/\1_\2/)' x&lt;BR /&gt;&lt;BR /&gt;Using s/x/y/g did only replace one space.&lt;BR /&gt;&lt;BR /&gt;The while forces the repeated attempts.&lt;BR /&gt;&lt;BR /&gt;(\[\S*?)  looks for, and remembers in \1 an opening box and any number of non-whitespace&lt;BR /&gt;&lt;BR /&gt;\s  followed by whitespace &lt;BR /&gt;&lt;BR /&gt;([^\[]+\]) followed by any number non-open-box, followed by a closing box, which is all remembered in \2.&lt;BR /&gt;&lt;BR /&gt;Just using [^x]+ but the x is a [ and needs to be escaped giving [^\[]+&lt;BR /&gt;&lt;BR /&gt;Replace the lot by \1, an _ and \2.&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.</description>
      <pubDate>Fri, 25 May 2007 21:18:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-and-replace-character/m-p/4007400#M96233</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2007-05-25T21:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: sed and replace character</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-and-replace-character/m-p/4007401#M96234</link>
      <description>With sed command use&lt;BR /&gt;&lt;BR /&gt;sed 's/ /_/g;s/_=_/ = /g;s/\]_/\] /g' input_file&lt;BR /&gt;&lt;BR /&gt;OUTPUT:&lt;BR /&gt;   f_name = [kamal_ahmed_kamal] job = [sysadmin]&lt;BR /&gt;   address = [30_A_anything_Street]&lt;BR /&gt;</description>
      <pubDate>Mon, 28 May 2007 02:35:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-and-replace-character/m-p/4007401#M96234</guid>
      <dc:creator>MurugesanGCT</dc:creator>
      <dc:date>2007-05-28T02:35:18Z</dc:date>
    </item>
  </channel>
</rss>

