<?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: sed brainstorming in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058814#M138282</link>
    <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Here's one possible way with 'awk' and a shell wrapper:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;EXP="export ECRAN=\`who am I -R | sed 's/.*(\([a-zA-Z0-9]*\)\..*/\1/'\`"&lt;BR /&gt;awk -v EXP="${EXP}" '&lt;BR /&gt;  BEGIN{ B=0 }&lt;BR /&gt;  /PATH=/ {&lt;BR /&gt;    if (B==0) { B=1;print EXP }&lt;BR /&gt;  }&lt;BR /&gt;  {print $0}&lt;BR /&gt;' $1 &amp;gt; $1.new&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;NOTE that the "ticks" are escaped with the backslash in the 'EXP' variable assignment.  Pass the name of the user's profile to the shell script.  The modified file is titled the same with a ".new" extension.&lt;BR /&gt;&lt;BR /&gt;I chose to insert the export before the first PATH declaration.  You could do it anywhere.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Thu, 28 Aug 2003 13:35:14 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2003-08-28T13:35:14Z</dc:date>
    <item>
      <title>sed brainstorming</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058809#M138277</link>
      <description>&lt;BR /&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;I need to add in a lots of .profile one line which is:&lt;BR /&gt;&lt;BR /&gt;export ECRAN=`who am I -R | sed 's/.*(\([a-zA-Z0-9]*\)\..*/\1/'`&lt;BR /&gt;&lt;BR /&gt;(the line must be insert before a match)&lt;BR /&gt;I search a good script using sed or awk which looks like that:&lt;BR /&gt;&lt;BR /&gt;for i in [ .. . profile] ; do&lt;BR /&gt;sed 's/match/iexport ECRAN=`....' $i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;this one didn't work because there are many special char in the string :&lt;BR /&gt;Maybe someone can help me.&lt;BR /&gt;Thanks</description>
      <pubDate>Thu, 28 Aug 2003 12:18:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058809#M138277</guid>
      <dc:creator>Alexandre Arents</dc:creator>
      <dc:date>2003-08-28T12:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: sed brainstorming</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058810#M138278</link>
      <description>why don't you use Perl, it has a better reg ex engine than sed.&lt;BR /&gt;&lt;BR /&gt;you will need to spool the .profile files either in memory or to a temp file.&lt;BR /&gt;&lt;BR /&gt;send what you want done than I'll code it for you.&lt;BR /&gt;&lt;BR /&gt;life is good here&lt;BR /&gt;Donny</description>
      <pubDate>Thu, 28 Aug 2003 12:22:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058810#M138278</guid>
      <dc:creator>Donny Jekels</dc:creator>
      <dc:date>2003-08-28T12:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: sed brainstorming</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058811#M138279</link>
      <description>Well you can use vi for this can of job&lt;BR /&gt;keep your loop&lt;BR /&gt;add a match command for these .profile&lt;BR /&gt;and&lt;BR /&gt;&lt;BR /&gt;vi .profile &lt;MYCOM&gt;/dev/null&lt;BR /&gt;&lt;BR /&gt;with mycom :&lt;BR /&gt;/&lt;YOUR match=""&gt;&lt;BR /&gt;:r tpl1&lt;BR /&gt;:wq&lt;BR /&gt;&lt;BR /&gt;and tpl1 is :&lt;BR /&gt;export ECRAN=`who am I -R | sed 's/.*(\([a-zA-Z0-9]*\)\..*/\1/'` &lt;BR /&gt;&lt;BR /&gt;Of course if you navigate in subdir you would have to give full path for these files.&lt;BR /&gt;&lt;BR /&gt;this will add the comand lie after the 1st match.&lt;BR /&gt;If none it would add the line on top of your .profile so better if you check beforehand with say "grep"&lt;BR /&gt;&lt;BR /&gt;It's all yours&lt;BR /&gt;&lt;BR /&gt;Rgds.&lt;BR /&gt;JL&lt;/YOUR&gt;&lt;/MYCOM&gt;</description>
      <pubDate>Thu, 28 Aug 2003 12:39:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058811#M138279</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2003-08-28T12:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: sed brainstorming</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058812#M138280</link>
      <description>If I had to do mass changes on all user profiles, I would do the following-&lt;BR /&gt;&lt;BR /&gt;for i in /home/*/.profile ; do&lt;BR /&gt;perl -p -i -e 'print "export ECRAN=\`who am I -R | sed \'s/.*(\\([a-zA-Z0-9]*\)\..*/\1/\'\`\n" if /match/'&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This will insert the "export" line prior to any line that contains the text "match". I had to add extra "\" to the export so that perl would pass the characters asis. They of course will disappear in the resultant file.&lt;BR /&gt;&lt;BR /&gt;The a nifty option to perl is called in-place changes. The -i option automatically creates a temp file, and sends the output there. At the end of the process, perl will make the temp file the "new" file. You also have the option to rename the original, ie -i.bu will rename original by appending ".bu".&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 28 Aug 2003 13:25:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058812#M138280</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-08-28T13:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: sed brainstorming</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058813#M138281</link>
      <description>Whoops, I forgot to add the filename as part of the command.&lt;BR /&gt;&lt;BR /&gt;for i in /home/*/.profile ; do &lt;BR /&gt;perl -p -i -e 'print "export ECRAN=\`who am I -R | sed \'s/.*(\\([a-zA-Z0-9]*\)\..*/\1/\'\`\n" if /match/' $i&lt;BR /&gt;done &lt;BR /&gt;</description>
      <pubDate>Thu, 28 Aug 2003 13:26:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058813#M138281</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-08-28T13:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: sed brainstorming</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058814#M138282</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Here's one possible way with 'awk' and a shell wrapper:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;EXP="export ECRAN=\`who am I -R | sed 's/.*(\([a-zA-Z0-9]*\)\..*/\1/'\`"&lt;BR /&gt;awk -v EXP="${EXP}" '&lt;BR /&gt;  BEGIN{ B=0 }&lt;BR /&gt;  /PATH=/ {&lt;BR /&gt;    if (B==0) { B=1;print EXP }&lt;BR /&gt;  }&lt;BR /&gt;  {print $0}&lt;BR /&gt;' $1 &amp;gt; $1.new&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;NOTE that the "ticks" are escaped with the backslash in the 'EXP' variable assignment.  Pass the name of the user's profile to the shell script.  The modified file is titled the same with a ".new" extension.&lt;BR /&gt;&lt;BR /&gt;I chose to insert the export before the first PATH declaration.  You could do it anywhere.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 28 Aug 2003 13:35:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058814#M138282</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2003-08-28T13:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: sed brainstorming</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058815#M138283</link>
      <description>If you need this variable to be defined in lots of different .profiles, why not just put the line once in /etc/profile, which is read by every .profile.&lt;BR /&gt;&lt;BR /&gt;This makes maintenance a little easier, in case you need to make a change in the future.</description>
      <pubDate>Fri, 29 Aug 2003 08:12:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/sed-brainstorming/m-p/3058815#M138283</guid>
      <dc:creator>Martin Robinson</dc:creator>
      <dc:date>2003-08-29T08:12:02Z</dc:date>
    </item>
  </channel>
</rss>

