<?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: ksh? inserting line into files in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883824#M704363</link>
    <description>see last posting :)</description>
    <pubDate>Thu, 03 Feb 2005 17:21:51 GMT</pubDate>
    <dc:creator>Florian Heigl (new acc)</dc:creator>
    <dc:date>2005-02-03T17:21:51Z</dc:date>
    <item>
      <title>ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883815#M704354</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I know this is an easy one, and will just say that I caught a flu which makes my head ache a bit too much.&lt;BR /&gt;&lt;BR /&gt;I need to insert a css reference into a LOT of html files.&lt;BR /&gt;&lt;BR /&gt;so far I've thought about &lt;BR /&gt;mv foo.html foo.html.bak&lt;BR /&gt;while read line &amp;lt; foo.html.bak&lt;BR /&gt; do&lt;BR /&gt;  echo $line &amp;gt;&amp;gt; foo.html&lt;BR /&gt;  if [ echo $line | grep '' 2&amp;gt;dev/null 1&amp;gt;/dev/null ] &lt;BR /&gt;   then &lt;BR /&gt;    echo "$CSS_THINGY" &amp;gt;&amp;gt;foo.html&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;but somehow I get the feeling that this might&lt;BR /&gt;blow up or just be a very strange way of doing it.&lt;BR /&gt;&lt;BR /&gt;I'd love some recommendations!</description>
      <pubDate>Wed, 02 Feb 2005 22:26:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883815#M704354</guid>
      <dc:creator>Florian Heigl (new acc)</dc:creator>
      <dc:date>2005-02-02T22:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883816#M704355</link>
      <description>Permissions of the new foo.html may not match the original...  instead of mv, how about cp then null the original file?&lt;BR /&gt;&lt;BR /&gt;cp foo.html foo.html.bak&lt;BR /&gt;&amp;gt; foo.html&lt;BR /&gt;while read line &amp;lt; foo.html.bak&lt;BR /&gt;do&lt;BR /&gt;echo $line &amp;gt;&amp;gt; foo.html&lt;BR /&gt;if [ echo $line | grep '' 2&amp;gt;dev/null 1&amp;gt;/dev/null ]&lt;BR /&gt;then&lt;BR /&gt;echo "$CSS_THINGY" &amp;gt;&amp;gt;foo.html&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;-denver</description>
      <pubDate>Wed, 02 Feb 2005 22:47:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883816#M704355</guid>
      <dc:creator>Denver Osborn</dc:creator>
      <dc:date>2005-02-02T22:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883817#M704356</link>
      <description>okay :)&lt;BR /&gt;&lt;BR /&gt;I chose mv because it's not updating the original file at all, but forgot about the new file.&lt;BR /&gt;then a&lt;BR /&gt;cp -p foo.html.bak foo.html and a&lt;BR /&gt;&amp;gt; foo.html&lt;BR /&gt;would be needed to keep everything in sync.&lt;BR /&gt;&lt;BR /&gt;also, I noticed the if clause must read&lt;BR /&gt; if [` echo $line | grep '' 2&amp;gt;dev/null 1&amp;gt;/dev/null `]&lt;BR /&gt;&lt;BR /&gt;I'll try it later, right now I'm just to dizzy.</description>
      <pubDate>Wed, 02 Feb 2005 22:56:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883817#M704356</guid>
      <dc:creator>Florian Heigl (new acc)</dc:creator>
      <dc:date>2005-02-02T22:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883818#M704357</link>
      <description>same here, it's past my bedtime. I didn't bother to test it before posting... just did a cut/paste to point out cp -vs- mv.&lt;BR /&gt;&lt;BR /&gt;I'm sure one of the perl gurus will wake up and solve this one w/ a few lines of perl script for you.&lt;BR /&gt;&lt;BR /&gt;-denver</description>
      <pubDate>Wed, 02 Feb 2005 22:59:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883818#M704357</guid>
      <dc:creator>Denver Osborn</dc:creator>
      <dc:date>2005-02-02T22:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883819#M704358</link>
      <description>I knew I shouldn't trust myself :)&lt;BR /&gt;&lt;BR /&gt;-su[4]: dev/null: cannot create [No such file or directory]&lt;BR /&gt;-su[4]: []: not found [No such file or directory]&lt;BR /&gt;-su[4]: dev/null: cannot create [No such file or directory]&lt;BR /&gt;-su[4]: []: not found [No such file or directory]&lt;BR /&gt;-su[4]: dev/null: cannot create [No such file or directory]&lt;BR /&gt;-su[4]: []: not found [No such file or directory]&lt;BR /&gt;-su[4]: dev/null: cannot create [No such file or directory]&lt;BR /&gt;-su[4]: []: not found [No such file or directory]&lt;BR /&gt;-su[4]: dev/null: cannot create [No such file or directory]&lt;BR /&gt;&lt;BR /&gt;(see You in 12 hrs :)</description>
      <pubDate>Wed, 02 Feb 2005 22:59:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883819#M704358</guid>
      <dc:creator>Florian Heigl (new acc)</dc:creator>
      <dc:date>2005-02-02T22:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883820#M704359</link>
      <description>Replace :&lt;BR /&gt;--------&lt;BR /&gt;if [ echo $line | grep '' 2&amp;gt;dev/null 1&amp;gt;/dev/null ] &lt;BR /&gt;then&lt;BR /&gt;     .... &lt;YOUR script="" here=""&gt; ....&lt;BR /&gt;-----------  &lt;BR /&gt;&lt;BR /&gt;with :&lt;BR /&gt;&lt;BR /&gt;-------------&lt;BR /&gt; echo $line | grep -q ''&lt;BR /&gt; if [ $? -eq 0 ]&lt;BR /&gt; then&lt;BR /&gt;    ......&lt;YOUR script="" here=""&gt; ....  &lt;BR /&gt;-----------&lt;BR /&gt;&lt;BR /&gt;BTW, the error messages printed by your script was&lt;BR /&gt;bacause of typo ('dev/null' instead of '/dev/null')&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;&lt;/YOUR&gt;&lt;/YOUR&gt;</description>
      <pubDate>Wed, 02 Feb 2005 23:21:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883820#M704359</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-02-02T23:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883821#M704360</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;required perl alternative:&lt;BR /&gt;&lt;BR /&gt;perl -i -ne 'print; print "css\n" if (/&amp;lt;\/title/)' x.html&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If you'd need a line before a marker it reduces to:&lt;BR /&gt;&lt;BR /&gt;perl -i -pe 'print "css\n" if (/&amp;lt;\/title/)' x.html&lt;BR /&gt;&lt;BR /&gt;The "-i" creates a temp file. The alternative is the old&lt;BR /&gt;perl -ne 'print; print "css\n" if (/&amp;lt;\/title/)' &amp;lt; x.bak &amp;gt; x.html&lt;BR /&gt;&lt;BR /&gt;you can pull in an shell symbol through $ENV{name}&lt;BR /&gt;&lt;BR /&gt;perl -i -ne 'print; print "$ENV{\"XX\"}\n" if (/&amp;lt;\/title/)' x.tmp&lt;BR /&gt;&lt;BR /&gt;and one of many awk solutions:&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN {css=ENVIRON["CSS_THINGY"]}{print}/&amp;lt;\/title&amp;gt;/{print css}' x.tmp&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;CHeers,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Feb 2005 00:58:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883821#M704360</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-02-03T00:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883822#M704361</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;2&amp;gt;dev/null 1&amp;gt;/dev/null &lt;BR /&gt;There is a / missing hence the errors.&lt;BR /&gt;&lt;BR /&gt;Secondly, if you run a faulty script twice, you loose your original.&lt;BR /&gt;&lt;BR /&gt;what about&lt;BR /&gt;awk '/&amp;lt;\/title&amp;gt;/ {print $0;print "CSS_THINGY";next;}{print $0}' foo.html&lt;BR /&gt;&lt;BR /&gt;greetings,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Feb 2005 08:20:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883822#M704361</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2005-02-03T08:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883823#M704362</link>
      <description>Biswajit - thanks for the grep -q :)&lt;BR /&gt;&lt;BR /&gt;And Hein - thank You for trying to build something more reasonable than that 'late night dilemma' I made - I chose Your awk solution, it takes well below a second for 100 files, which is very acceptable!&lt;BR /&gt;&lt;BR /&gt;Michael - You've been right about the fact that I'd lose the originals by every second run. It was no issue because the files will be regenerated quite often but it's well worth noting.</description>
      <pubDate>Thu, 03 Feb 2005 17:19:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883823#M704362</guid>
      <dc:creator>Florian Heigl (new acc)</dc:creator>
      <dc:date>2005-02-03T17:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: ksh? inserting line into files</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883824#M704363</link>
      <description>see last posting :)</description>
      <pubDate>Thu, 03 Feb 2005 17:21:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-inserting-line-into-files/m-p/4883824#M704363</guid>
      <dc:creator>Florian Heigl (new acc)</dc:creator>
      <dc:date>2005-02-03T17:21:51Z</dc:date>
    </item>
  </channel>
</rss>

