<?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: Pattern Finding &amp;amp; replacing tool in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224821#M893419</link>
    <description>Hi Curt,&lt;BR /&gt;&lt;BR /&gt;Good work &amp;amp; experience !!!!!!&lt;BR /&gt;&lt;BR /&gt;Really, I am beginner in HP-UX and in even ITRC at all.&lt;BR /&gt;&lt;BR /&gt;what about this :&lt;BR /&gt;&lt;BR /&gt;I created a text file with two fields, first is the name &amp;amp; the second is the corresponding code, as follows :&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;opra            6055&lt;BR /&gt;pyre            6056&lt;BR /&gt;pyre2           22161&lt;BR /&gt;pyrw            6057&lt;BR /&gt;rams            6058&lt;BR /&gt;remaya          22160&lt;BR /&gt;tagamoa         25206&lt;BR /&gt;tora            25209&lt;BR /&gt;zamalek         23569&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;. and so on,&lt;BR /&gt;I called this file swcodes&lt;BR /&gt;this is my script (really, first script in unix) :&lt;BR /&gt;&lt;BR /&gt;#while read x y&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt;  ls $x*.gz &amp;gt; list&lt;BR /&gt;&amp;gt;     for i in $(&lt;LIST&gt;&lt;/LIST&gt;&amp;gt;       do&lt;BR /&gt;&amp;gt;         print $i | k=$(sed 's/'$x'/'$y'/')&lt;BR /&gt;&amp;gt;         mv $i $k&lt;BR /&gt;&amp;gt;       done&lt;BR /&gt;&amp;gt; done &amp;lt; swcodes&lt;BR /&gt;&lt;BR /&gt;it runs properly !!!! &lt;BR /&gt;If you have any comments, enhancements, please don't hesitate to inform me.&lt;BR /&gt;&lt;BR /&gt;Thank you too much.&lt;BR /&gt;&lt;BR /&gt;Tamer.</description>
    <pubDate>Mon, 22 Mar 2004 05:10:33 GMT</pubDate>
    <dc:creator>Tamer Shaalan</dc:creator>
    <dc:date>2004-03-22T05:10:33Z</dc:date>
    <item>
      <title>Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224812#M893410</link>
      <description>Hi all of you,&lt;BR /&gt;&lt;BR /&gt;I know it is a basic question.&lt;BR /&gt;&lt;BR /&gt;I want a tool(command) to find &amp;amp; replace a pattern from a command line(I tried "sed", but the i/p of sed is treated to be a file name)</description>
      <pubDate>Sun, 21 Mar 2004 12:30:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224812#M893410</guid>
      <dc:creator>Tamer Shaalan</dc:creator>
      <dc:date>2004-03-21T12:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224813#M893411</link>
      <description>do you have an example of what your trying to do.&lt;BR /&gt;&lt;BR /&gt;sed, awk, perl, ex, etc can do pattern matching and substitution.&lt;BR /&gt;&lt;BR /&gt;I'm those of the forum can assist if we had more information on what your trying to accomplish</description>
      <pubDate>Sun, 21 Mar 2004 12:49:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224813#M893411</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-03-21T12:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224814#M893412</link>
      <description>OK Curt,&lt;BR /&gt;&lt;BR /&gt;what I have is the following :&lt;BR /&gt;&lt;BR /&gt;I have large number of files with names such yhat: NameDate.gz for example :&lt;BR /&gt;&lt;BR /&gt;zamalek040311.gz&lt;BR /&gt;zamalek040312.gz&lt;BR /&gt;zamalek040313.gz&lt;BR /&gt;zamalek040314.gz&lt;BR /&gt;zamalek040315.gz&lt;BR /&gt;zamalek040316.gz&lt;BR /&gt;zamalek040317.gz&lt;BR /&gt;zamalek040318.gz&lt;BR /&gt;zamalek040319.gz&lt;BR /&gt;zamalek040320.gz&lt;BR /&gt;&lt;BR /&gt;and &lt;BR /&gt;&lt;BR /&gt;giza040311.gz&lt;BR /&gt;giza040312.gz&lt;BR /&gt;giza040313.gz&lt;BR /&gt;giza040314.gz&lt;BR /&gt;giza040315.gz&lt;BR /&gt;giza040317.gz&lt;BR /&gt;giza040318.gz&lt;BR /&gt;giza040319.gz&lt;BR /&gt;giza040320.gz&lt;BR /&gt;&lt;BR /&gt;you see that the 1st part of the name is a certain name(related to data sourec) and the rest is the dae of this file.&lt;BR /&gt;&lt;BR /&gt;what is required ??????&lt;BR /&gt;&lt;BR /&gt;to exchnge the fisrt part ( zamalek or giza) with a corresponding code as&lt;BR /&gt;&lt;BR /&gt;zamalek will be 23ca3&lt;BR /&gt;giza will be 25bc6 and so on.&lt;BR /&gt;&lt;BR /&gt;have you any ideas.&lt;BR /&gt;&lt;BR /&gt;Tamer.</description>
      <pubDate>Sun, 21 Mar 2004 13:01:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224814#M893412</guid>
      <dc:creator>Tamer Shaalan</dc:creator>
      <dc:date>2004-03-21T13:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224815#M893413</link>
      <description>lots of ways to do that&lt;BR /&gt;&lt;BR /&gt;olddir=$(pwd)&lt;BR /&gt;cd yourdir&lt;BR /&gt;name=giza&lt;BR /&gt;newname="25bc6"&lt;BR /&gt;&lt;BR /&gt;ls ${name}* |&lt;BR /&gt;while read fname1&lt;BR /&gt;do&lt;BR /&gt;newfile=$(print $fname1 | sed "s|$name|$newname|"&lt;BR /&gt;#mv fname1 newfile&lt;BR /&gt;done&lt;BR /&gt;cd $olddir&lt;BR /&gt;&lt;BR /&gt;instead of using sed you could&lt;BR /&gt;awk "{sub($name,$newname);print $0;}"&lt;BR /&gt;or perl -ne "s/$name/$newname/;print;"</description>
      <pubDate>Sun, 21 Mar 2004 13:19:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224815#M893413</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-03-21T13:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224816#M893414</link>
      <description>looks like a couple of characters didn't get there&lt;BR /&gt;&lt;BR /&gt;newfile=$(print $fname1 | sed "s|$name|$newname|"&lt;BR /&gt;#mv fname1 newfile&lt;BR /&gt;&lt;BR /&gt;should be&lt;BR /&gt;&lt;BR /&gt;newfile=$(print $fname1 | sed "s|$name|$newname|")&lt;BR /&gt;#i left off the ) ont he above line&lt;BR /&gt;#and the $'s before the filenamess below&lt;BR /&gt;print $fname1 $newfile&lt;BR /&gt;#mv $fname1 $newfile&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Mar 2004 13:25:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224816#M893414</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-03-21T13:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224817#M893415</link>
      <description>Hi Curt,&lt;BR /&gt;&lt;BR /&gt;many Thanks for you for helping me !!!!!&lt;BR /&gt;&lt;BR /&gt;what about this :&lt;BR /&gt;&lt;BR /&gt;# ls giza* &amp;gt; list&lt;BR /&gt;# for i in $(&lt;LIST&gt;&lt;/LIST&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; print $i | k=$(sed 's/zamalek/code/')&lt;BR /&gt;&amp;gt; mv $i $k&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;BR /&gt;It is easily running &lt;BR /&gt;&lt;BR /&gt;what I raelly was missing is :&lt;BR /&gt;print $i&lt;BR /&gt;&lt;BR /&gt;before you replay to me, I used :&lt;BR /&gt;&amp;gt; sed 's/zamalek/code/' $i&lt;BR /&gt;&lt;BR /&gt;which gives error ( because sed was replacing inside the file itself not its name !!!!!!!!! )&lt;BR /&gt;when I replaced with print $i and piping, it runs properly .&lt;BR /&gt;&lt;BR /&gt;the last question !!!!!&lt;BR /&gt;&lt;BR /&gt;If I have many patterns which must be replaced with another different codes, I need to see your intelligent solution???&lt;BR /&gt;I already did it !!!!! &lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;BR /&gt;&lt;BR /&gt;Tamer.</description>
      <pubDate>Sun, 21 Mar 2004 13:52:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224817#M893415</guid>
      <dc:creator>Tamer Shaalan</dc:creator>
      <dc:date>2004-03-21T13:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224818#M893416</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;set -A    names zamalek giza&lt;BR /&gt;set -A newNames 23ca3   25bc6&lt;BR /&gt;&lt;BR /&gt;# might want to do some error checking&lt;BR /&gt;# on your names here&lt;BR /&gt;# like size of names and newNames are the same etc&lt;BR /&gt;&lt;BR /&gt;olddir=$(pwd)&lt;BR /&gt;cd yourdir&lt;BR /&gt;x=0&lt;BR /&gt;while (( $x &amp;lt; ${#names[@]} ))&lt;BR /&gt;do&lt;BR /&gt;ls "${names[$x]}*" |&lt;BR /&gt;while read fname&lt;BR /&gt;do&lt;BR /&gt;newfname=$(print $fname | sed "s|${names[$x]}|${newNames[$x]}|"&lt;BR /&gt;mv $fname $newfname&lt;BR /&gt;done&lt;BR /&gt;done&lt;BR /&gt;cd $olddir&lt;BR /&gt;&lt;BR /&gt;you might try a bit different algorithm that doesn't so an ls for every name, that would make things faster.&lt;BR /&gt;&lt;BR /&gt;you could do this also all within awk or perl.  And, with associative arrays it would be a bit easier to do.</description>
      <pubDate>Sun, 21 Mar 2004 14:50:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224818#M893416</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-03-21T14:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224819#M893417</link>
      <description>oops forgot to increment my loop counter&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;x=$(( $x + 1 ))&lt;BR /&gt;done&lt;BR /&gt;cd $olddir&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Mar 2004 14:53:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224819#M893417</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-03-21T14:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224820#M893418</link>
      <description>what about this :&lt;BR /&gt;&lt;BR /&gt;# ls giza* &amp;gt; list&lt;BR /&gt;# for i in $(&lt;LIST&gt;&lt;/LIST&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; what about this :&lt;BR /&gt;&lt;BR /&gt;# ls giza* &amp;gt; list&lt;BR /&gt;# for i in $(&lt;LIST&gt;&lt;/LIST&gt;&amp;gt; do&lt;BR /&gt;&amp;gt; print $i | k=$(sed 's/zamalek/code/')&lt;BR /&gt;&amp;gt; mv $i $k&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&amp;gt; mv $i $k&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;&lt;BR /&gt;well generally it is unnecessary to create a list.  of course for troubleshooting or auditing it can be helpful to do such checkpointing.&lt;BR /&gt;&lt;BR /&gt;for i in $(ls giza*)&lt;BR /&gt;&lt;BR /&gt;will run faster, because your not creating a file.  and you don't have to worry about coordinating with other programs that could write to "list" and corrupt your data.&lt;BR /&gt;&lt;BR /&gt;and only excepts a finite amount of data, i.e. there is a limit in how many character "ls giza*" can return.  it is a large amount, but when you don't know how much data is going to be returned reading from a pipe is preferred. (at least by me it is). so i'd do something like this instead&lt;BR /&gt;ls giza* |&lt;BR /&gt;while read fname&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;and i think instead of &lt;BR /&gt;&amp;gt; print $i | k=$(sed 's/zamalek/code/')&lt;BR /&gt;you must of meant&lt;BR /&gt;k=$(print $i | sed 's/giza/code/')&lt;BR /&gt;</description>
      <pubDate>Sun, 21 Mar 2004 15:37:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224820#M893418</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-03-21T15:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Pattern Finding &amp; replacing tool</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224821#M893419</link>
      <description>Hi Curt,&lt;BR /&gt;&lt;BR /&gt;Good work &amp;amp; experience !!!!!!&lt;BR /&gt;&lt;BR /&gt;Really, I am beginner in HP-UX and in even ITRC at all.&lt;BR /&gt;&lt;BR /&gt;what about this :&lt;BR /&gt;&lt;BR /&gt;I created a text file with two fields, first is the name &amp;amp; the second is the corresponding code, as follows :&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;opra            6055&lt;BR /&gt;pyre            6056&lt;BR /&gt;pyre2           22161&lt;BR /&gt;pyrw            6057&lt;BR /&gt;rams            6058&lt;BR /&gt;remaya          22160&lt;BR /&gt;tagamoa         25206&lt;BR /&gt;tora            25209&lt;BR /&gt;zamalek         23569&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;. and so on,&lt;BR /&gt;I called this file swcodes&lt;BR /&gt;this is my script (really, first script in unix) :&lt;BR /&gt;&lt;BR /&gt;#while read x y&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt;  ls $x*.gz &amp;gt; list&lt;BR /&gt;&amp;gt;     for i in $(&lt;LIST&gt;&lt;/LIST&gt;&amp;gt;       do&lt;BR /&gt;&amp;gt;         print $i | k=$(sed 's/'$x'/'$y'/')&lt;BR /&gt;&amp;gt;         mv $i $k&lt;BR /&gt;&amp;gt;       done&lt;BR /&gt;&amp;gt; done &amp;lt; swcodes&lt;BR /&gt;&lt;BR /&gt;it runs properly !!!! &lt;BR /&gt;If you have any comments, enhancements, please don't hesitate to inform me.&lt;BR /&gt;&lt;BR /&gt;Thank you too much.&lt;BR /&gt;&lt;BR /&gt;Tamer.</description>
      <pubDate>Mon, 22 Mar 2004 05:10:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/pattern-finding-amp-replacing-tool/m-p/3224821#M893419</guid>
      <dc:creator>Tamer Shaalan</dc:creator>
      <dc:date>2004-03-22T05:10:33Z</dc:date>
    </item>
  </channel>
</rss>

