<?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 Re: find and replace for strings in shell scripts in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317790#M876902</link>
    <description>Or if you use Ionut's prettier awk script, you need to add the output field separator:&lt;BR /&gt;&lt;BR /&gt;awk -F\| '{OFS="|";$4="your_string";print}' your_file</description>
    <pubDate>Tue, 29 Jun 2004 21:23:30 GMT</pubDate>
    <dc:creator>Allan Prentice</dc:creator>
    <dc:date>2004-06-29T21:23:30Z</dc:date>
    <item>
      <title>find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317783#M876895</link>
      <description>I have a file , and each line has values seperated by pipe"|".&lt;BR /&gt;&lt;BR /&gt;Now I have to replace the string after the 3th Pipe, with another string. &lt;BR /&gt;How do I do the same in unix shell script?&lt;BR /&gt;&lt;BR /&gt;Suposse the file has contents as below.[ 2 lines]&lt;BR /&gt;&lt;BR /&gt;B100|ABCD|1234|AM20|TEST&lt;BR /&gt;B100|ABCDAM20|1234|AM20|TEST&lt;BR /&gt;&lt;BR /&gt;Now I want to replace the AM20 with TPID after the 3rd Pipe, and not in any other place &lt;BR /&gt;&lt;BR /&gt;if I use sed command like this..&lt;BR /&gt;echo $LINE | sed -e 's/AM20/TPID/' &amp;gt;&amp;gt;CPQFILE.tmp&lt;BR /&gt;&lt;BR /&gt;it will also replace ABCDAM20 in the second line as ABCDTPID which I DONT want to happen..&lt;BR /&gt;PS: I am reading the file line by line and outputting in a temp file.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Jun 2004 05:00:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317783#M876895</guid>
      <dc:creator>Prasad Govenkar</dc:creator>
      <dc:date>2004-06-29T05:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317784#M876896</link>
      <description>Hai,&lt;BR /&gt;&lt;BR /&gt; We can use the check pattern as |AM20|. It will be replaced with |TPID|&lt;BR /&gt;&lt;BR /&gt; echo &lt;FILENAME&gt; | sed -e 's/|AM20|/|TPID|/g'&lt;BR /&gt;&lt;BR /&gt; It will do globally on the full file.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Muthukumar.&lt;/FILENAME&gt;</description>
      <pubDate>Tue, 29 Jun 2004 05:08:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317784#M876896</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-06-29T05:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317785#M876897</link>
      <description>Try this: -&lt;BR /&gt;&lt;BR /&gt;echo $LINE | awk -F\| 'BEGIN{OFS="|"}$4=="AM20"{$4="TPID"}{print $0}'</description>
      <pubDate>Tue, 29 Jun 2004 05:12:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317785#M876897</guid>
      <dc:creator>Simon Hargrave</dc:creator>
      <dc:date>2004-06-29T05:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317786#M876898</link>
      <description>Hai,&lt;BR /&gt;&lt;BR /&gt; We can do the above with tr command too.&lt;BR /&gt;Use the command setup as like,&lt;BR /&gt;&lt;BR /&gt; echo $LINE | tr -c '|AM20|' '|TPID|'&lt;BR /&gt;&lt;BR /&gt; It will work too.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Muthukumar.</description>
      <pubDate>Tue, 29 Jun 2004 05:12:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317786#M876898</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-06-29T05:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317787#M876899</link>
      <description>hi,&lt;BR /&gt; &lt;BR /&gt;with vi:&lt;BR /&gt;%s/\(^.*|.*|.*|\)AM20\(|.*\)/\1TPID\2&lt;BR /&gt; &lt;BR /&gt;with ed:&lt;BR /&gt;,s/\(^.*|.*|.*|\)AM20\(|.*\)/\1XXX\2&lt;BR /&gt; &lt;BR /&gt;good luck,&lt;BR /&gt;Thierry.</description>
      <pubDate>Tue, 29 Jun 2004 05:13:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317787#M876899</guid>
      <dc:creator>Thierry Poels_1</dc:creator>
      <dc:date>2004-06-29T05:13:46Z</dc:date>
    </item>
    <item>
      <title>Re: find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317788#M876900</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;what about using awk?&lt;BR /&gt;&lt;BR /&gt;awk -F\| '{$4="your_string";print}' your_file</description>
      <pubDate>Tue, 29 Jun 2004 19:12:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317788#M876900</guid>
      <dc:creator>Ionut Grigorescu_2</dc:creator>
      <dc:date>2004-06-29T19:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317789#M876901</link>
      <description>Try this, which doesn't care about the field contents:&lt;BR /&gt;&lt;BR /&gt;sed -e 's/^\([^|]*|[^|]*|[^|]*|\)\([^|]*\)\(.*\)$/\1NEWSTUFF\3/' &amp;lt; oldfile &amp;gt; newfile&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Jun 2004 21:16:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317789#M876901</guid>
      <dc:creator>Allan Prentice</dc:creator>
      <dc:date>2004-06-29T21:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317790#M876902</link>
      <description>Or if you use Ionut's prettier awk script, you need to add the output field separator:&lt;BR /&gt;&lt;BR /&gt;awk -F\| '{OFS="|";$4="your_string";print}' your_file</description>
      <pubDate>Tue, 29 Jun 2004 21:23:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317790#M876902</guid>
      <dc:creator>Allan Prentice</dc:creator>
      <dc:date>2004-06-29T21:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317791#M876903</link>
      <description>I like simons answer the best. You should give him 10 &lt;BR /&gt;&lt;BR /&gt;cut -f 1-3 -d"|" test &amp;gt; test1&lt;BR /&gt;&lt;BR /&gt;cut -f4 -d"|" test |sed -e"s/AM20/xxx/"&amp;gt; test2&lt;BR /&gt;&lt;BR /&gt;cut -f "5-" -d"|" test &amp;gt; test3&lt;BR /&gt;&lt;BR /&gt;paste -d "|" test1 test2 test3 &amp;gt; test&lt;BR /&gt;&lt;BR /&gt;Rory&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jun 2004 10:28:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317791#M876903</guid>
      <dc:creator>Rory R Hammond</dc:creator>
      <dc:date>2004-06-30T10:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: find and replace for strings in shell scripts</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317792#M876904</link>
      <description>nobody to promote perl ? here it is :&lt;BR /&gt;$&amp;gt;cat file&lt;BR /&gt;B100|ABCD|1234|AM20|TEST&lt;BR /&gt;B100|ABCDAM20|1234|AM20|TEST&lt;BR /&gt;$&amp;gt;cat run&lt;BR /&gt;#!/opt/perl/bin/perl&lt;BR /&gt;while (&lt;STDIN&gt;) {&lt;BR /&gt;  ($one,$two,$three,$four,$five)=split /\|/,$_;&lt;BR /&gt;  $four=~ s/^AM20$/TPID/g;&lt;BR /&gt;  print join '|', $one,$two,$three,$four,$five;&lt;BR /&gt;}&lt;BR /&gt;$&amp;gt;./run &amp;lt; file&lt;BR /&gt;B100|ABCD|1234|TPID|TEST&lt;BR /&gt;B100|ABCDAM20|1234|TPID|TEST&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;&lt;BR /&gt;Fred&lt;BR /&gt;&lt;/STDIN&gt;</description>
      <pubDate>Wed, 30 Jun 2004 10:53:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/find-and-replace-for-strings-in-shell-scripts/m-p/3317792#M876904</guid>
      <dc:creator>Fred Ruffet</dc:creator>
      <dc:date>2004-06-30T10:53:15Z</dc:date>
    </item>
  </channel>
</rss>

