<?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: newbie in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882197#M935201</link>
    <description>I need a simple script that will take one file that looks like this: &lt;BR /&gt;&lt;BR /&gt;F=121414 &lt;BR /&gt;&lt;BR /&gt;and compare it to a cross reference table &lt;BR /&gt;F=12 &lt;BR /&gt;&lt;BR /&gt;then rewrite the file like this &lt;BR /&gt;&lt;BR /&gt;12=121414 &lt;BR /&gt;</description>
    <pubDate>Wed, 15 Jan 2003 03:50:55 GMT</pubDate>
    <dc:creator>Allen Stacey</dc:creator>
    <dc:date>2003-01-15T03:50:55Z</dc:date>
    <item>
      <title>newbie</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882195#M935199</link>
      <description>I need some help on a shell script that will take one file which looks like this:&lt;BR /&gt;&lt;BR /&gt;F=13141&lt;BR /&gt;&lt;BR /&gt;and rewrite it to look like this&lt;BR /&gt;&lt;BR /&gt;14155=12141&lt;BR /&gt;&lt;BR /&gt;The same Letters will always have the same number tied to it.&lt;BR /&gt;&lt;BR /&gt;It also needs to do this on every file in the directory</description>
      <pubDate>Wed, 15 Jan 2003 03:35:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882195#M935199</guid>
      <dc:creator>Allen Stacey</dc:creator>
      <dc:date>2003-01-15T03:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: newbie</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882196#M935200</link>
      <description>Eloberate more. what exactly you want?&lt;BR /&gt;&lt;BR /&gt;you can do ll|grep "F="&lt;BR /&gt;&lt;BR /&gt;mv $1 another_file_name</description>
      <pubDate>Wed, 15 Jan 2003 03:45:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882196#M935200</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2003-01-15T03:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: newbie</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882197#M935201</link>
      <description>I need a simple script that will take one file that looks like this: &lt;BR /&gt;&lt;BR /&gt;F=121414 &lt;BR /&gt;&lt;BR /&gt;and compare it to a cross reference table &lt;BR /&gt;F=12 &lt;BR /&gt;&lt;BR /&gt;then rewrite the file like this &lt;BR /&gt;&lt;BR /&gt;12=121414 &lt;BR /&gt;</description>
      <pubDate>Wed, 15 Jan 2003 03:50:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882197#M935201</guid>
      <dc:creator>Allen Stacey</dc:creator>
      <dc:date>2003-01-15T03:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: newbie</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882198#M935202</link>
      <description>best to use sed or awk to do this.&lt;BR /&gt;&lt;BR /&gt;You can even be cheeky and do it using vi. I do it for billing info we send to our vendors to put a state code ($ENVIRONMENT) into each file, then concatenate all individual files into one big one.&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;update_file()&lt;BR /&gt;{&lt;BR /&gt;vi - $ENVIRONMENT &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;:1,%s/^/$ENVIRONMENT,/g&lt;BR /&gt;:wq!&lt;BR /&gt;EOF&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;for i in `ls -la [A-Z]* | awk '{print $9}'`&lt;BR /&gt;do&lt;BR /&gt;  ENVIRONMENT=$i&lt;BR /&gt;  update_file $ENVIRONMENT&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;for i in `ls -la [A-Z]* | awk '{print $9}'`&lt;BR /&gt;do&lt;BR /&gt;  cat $i &amp;gt;&amp;gt; BILLS&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;the bit that does it with vi is the "update_files" bit.&lt;BR /&gt;&lt;BR /&gt;So if you're familar with vi you can do it like:&lt;BR /&gt;&lt;BR /&gt;vi - FILE &amp;lt;&amp;lt; EOF&lt;BR /&gt;:1,%s/^F/12345/g&lt;BR /&gt;:1,%s/^G/67890/g&lt;BR /&gt;:wq!&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;That will do the one file. It&lt;BR /&gt;&lt;BR /&gt;: = vi command mode&lt;BR /&gt;:1 = go to first line&lt;BR /&gt;, = next command&lt;BR /&gt;%s = search&lt;BR /&gt;%s/^F/ = search from beginning of line for F (^ is anchor)&lt;BR /&gt;&lt;BR /&gt;%s/^F/123456/g = search from beginning of line for F and replace with 123456 for the entire file.&lt;BR /&gt;&lt;BR /&gt;This is using vi.....&lt;BR /&gt;&lt;BR /&gt;if you want to use sed, you'd do it like this:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;do_sub(){&lt;BR /&gt;while read a; do&lt;BR /&gt;sed 's/,b/,n/g' $a &amp;gt; $a.new&lt;BR /&gt;done&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;########################################&lt;BR /&gt;# Main script - messy but does the job #&lt;BR /&gt;########################################&lt;BR /&gt;ll *.ent | awk '{print $9}' &amp;gt; list.txt&lt;BR /&gt;&lt;BR /&gt;do_sub &amp;lt; list.txt&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This oen replaces ",b" with ",n" in all .ent files in a given directory. &lt;BR /&gt;&lt;BR /&gt;I could make it better, but I only ever needed to run it once. &lt;BR /&gt;&lt;BR /&gt;Once again, the sed statement is:&lt;BR /&gt;&lt;BR /&gt;s = search&lt;BR /&gt;/,b/ first thing to search for&lt;BR /&gt;/,n/ replace it with&lt;BR /&gt;g = entire file.&lt;BR /&gt;&lt;BR /&gt;Neither one is truly brillian and I'm sure you'll get a lot better answers from other people here, but I never have a need to run this stuff on a regular basis.&lt;BR /&gt;&lt;BR /&gt;Hope it helps anyhow.&lt;BR /&gt;&lt;BR /&gt;Scott.&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Jan 2003 03:51:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882198#M935202</guid>
      <dc:creator>Scott Van Kalken</dc:creator>
      <dc:date>2003-01-15T03:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: newbie</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882199#M935203</link>
      <description>Hi Allen-&lt;BR /&gt;&lt;BR /&gt;It's the cross-referencing that makes it tricky.  I understand your situation to be:&lt;BR /&gt;&lt;BR /&gt;You have a directory ("foodir/") which contains several files ("bar1", "bar2", bar3", etc").  You have one cross-reference file ("xref").  You want to rewrite each bar file individually base on xref.  The contents of xref look like:&lt;BR /&gt;&lt;BR /&gt;F=12&lt;BR /&gt;G=13&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;The bar files look like:&lt;BR /&gt;&lt;BR /&gt;F=12141&lt;BR /&gt;G=14234&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;The desired result is:&lt;BR /&gt;&lt;BR /&gt;12=12141&lt;BR /&gt;13=14234&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;There are no duplicate letters in xref, and it doesn't matter whether the bar files have dups.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Basically, you want to have the shell script do a loop through each file in the directory, and on each loop to process the files.  Because you're cross-referencing, it's easiest to process each file with the associative arrays (hashes) in perl or awk (more complex solutions use sed or the like instead).&lt;BR /&gt;&lt;BR /&gt;I'm attaching a heavily commented perl script which will handle the above.  It could be made shorter and less comprehensible (crunched down to one line illegible line in the extreme).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The solution using sed is shorter, but much, much less efficient because it has to go through each file and rewrite it once for each line in the xref file.  If you need, I can post it.&lt;BR /&gt;&lt;BR /&gt;-Scott-</description>
      <pubDate>Thu, 16 Jan 2003 18:47:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882199#M935203</guid>
      <dc:creator>Scott Corzine</dc:creator>
      <dc:date>2003-01-16T18:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: newbie</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882200#M935204</link>
      <description>Ok, duh, I forgot a trick that makes sed pretty easy and efficient too.&lt;BR /&gt;&lt;BR /&gt;First use sed to process the xref file into a fresh sed script:&lt;BR /&gt;&lt;BR /&gt;  sed -e 's@^\([A-Za-z]*\)=\([0-9]*\)$@s/^\1=/\2=/@' xref &amp;gt; xref.sed&lt;BR /&gt;&lt;BR /&gt;Then use that new sed script on each file:&lt;BR /&gt;&lt;BR /&gt;  for file in bar*&lt;BR /&gt;    do sed -f xref.sed $file &amp;gt; Done.$file&lt;BR /&gt;    done&lt;BR /&gt;&lt;BR /&gt;Explainations about the regular expression can be found in the perl script I posted earlier, note that perl and sed are a little different in their regular expressions (e.g. sed wants "\(" where as perl wants "(").&lt;BR /&gt;&lt;BR /&gt;You'll note that this is similar to Scott Van Kalken's vi commands, which is understandable because both sed and the vi line mode (: commands) are based on the same older editor ed.&lt;BR /&gt;&lt;BR /&gt;It's easy to get used to using a tool in a particular way, then forgetting what else it can do.  In this case I always use sed on the command line with "-e" and forgot that it can take a sed script as a file with "-f".&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Oh well, hope this helps,&lt;BR /&gt;-Scott-</description>
      <pubDate>Thu, 16 Jan 2003 19:06:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/newbie/m-p/2882200#M935204</guid>
      <dc:creator>Scott Corzine</dc:creator>
      <dc:date>2003-01-16T19:06:01Z</dc:date>
    </item>
  </channel>
</rss>

