<?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: Script to insert a line into a text file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-insert-a-line-into-a-text-file/m-p/2536516#M899418</link>
    <description>Sure no problem; something like this:&lt;BR /&gt;&lt;BR /&gt;TDIR=${TMPDIR:-/var/tmp}&lt;BR /&gt;PID=${$}&lt;BR /&gt;&lt;BR /&gt;T1=${TDIR}/X${PID}_1.txt&lt;BR /&gt;&lt;BR /&gt;ls | while read X&lt;BR /&gt;  do&lt;BR /&gt;     if [ -f "${X}" -a -w "${X}" -a -r "${X}" ]&lt;BR /&gt;       then&lt;BR /&gt;         L1=`line &amp;lt; ${X}`&lt;BR /&gt;         if [ "${L1}" = "test string" ]&lt;BR /&gt;           then&lt;BR /&gt;             echo "Insert this stuff" &amp;gt; $T1&lt;BR /&gt;             cat ${X} &amp;gt;&amp;gt; $T1&lt;BR /&gt;             mv $T1 $X&lt;BR /&gt;           fi&lt;BR /&gt;       fi&lt;BR /&gt;   done&lt;BR /&gt;&lt;BR /&gt;You might want to replace the = comparison with a grep -q and test the result.&lt;BR /&gt;&lt;BR /&gt;You could also do it with sed.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;</description>
    <pubDate>Tue, 05 Jun 2001 12:55:39 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2001-06-05T12:55:39Z</dc:date>
    <item>
      <title>Script to insert a line into a text file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-insert-a-line-into-a-text-file/m-p/2536515#M899417</link>
      <description>Hi Peeps, &lt;BR /&gt;&lt;BR /&gt;I need a script which will read the first line in every file in a directory and depending on the result, insert a line of text at the start of the file and save it. &lt;BR /&gt;Is there a way of doing this using a script instead of having to do it manually using vi? &lt;BR /&gt;&lt;BR /&gt;Many thanks in advance. &lt;BR /&gt;&lt;BR /&gt;Preet :-)</description>
      <pubDate>Tue, 05 Jun 2001 12:35:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-insert-a-line-into-a-text-file/m-p/2536515#M899417</guid>
      <dc:creator>Preet Dhillon</dc:creator>
      <dc:date>2001-06-05T12:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Script to insert a line into a text file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-insert-a-line-into-a-text-file/m-p/2536516#M899418</link>
      <description>Sure no problem; something like this:&lt;BR /&gt;&lt;BR /&gt;TDIR=${TMPDIR:-/var/tmp}&lt;BR /&gt;PID=${$}&lt;BR /&gt;&lt;BR /&gt;T1=${TDIR}/X${PID}_1.txt&lt;BR /&gt;&lt;BR /&gt;ls | while read X&lt;BR /&gt;  do&lt;BR /&gt;     if [ -f "${X}" -a -w "${X}" -a -r "${X}" ]&lt;BR /&gt;       then&lt;BR /&gt;         L1=`line &amp;lt; ${X}`&lt;BR /&gt;         if [ "${L1}" = "test string" ]&lt;BR /&gt;           then&lt;BR /&gt;             echo "Insert this stuff" &amp;gt; $T1&lt;BR /&gt;             cat ${X} &amp;gt;&amp;gt; $T1&lt;BR /&gt;             mv $T1 $X&lt;BR /&gt;           fi&lt;BR /&gt;       fi&lt;BR /&gt;   done&lt;BR /&gt;&lt;BR /&gt;You might want to replace the = comparison with a grep -q and test the result.&lt;BR /&gt;&lt;BR /&gt;You could also do it with sed.&lt;BR /&gt;&lt;BR /&gt;Regards, Clay&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Jun 2001 12:55:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-insert-a-line-into-a-text-file/m-p/2536516#M899418</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-06-05T12:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: Script to insert a line into a text file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-insert-a-line-into-a-text-file/m-p/2536517#M899419</link>
      <description>How about the following one liner...&lt;BR /&gt;&lt;BR /&gt;perl -p -i -e 'if ($. == 1 and /pattern/) { print "new line at start of file"}' *&lt;BR /&gt;&lt;BR /&gt;where pattern is a regexp to search for (use ! /pattern/ for negative sense).&lt;BR /&gt;&lt;BR /&gt;The * on the end will apply to all files in current directory. If you wish to save the original file change -i option to -i.old and this will save the original files with a .old extension.</description>
      <pubDate>Tue, 05 Jun 2001 13:36:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-insert-a-line-into-a-text-file/m-p/2536517#M899419</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2001-06-05T13:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script to insert a line into a text file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-insert-a-line-into-a-text-file/m-p/2536518#M899420</link>
      <description>cat file|while read i&lt;BR /&gt;do&lt;BR /&gt;echo $i &amp;gt;&amp;gt; file_new&lt;BR /&gt;echo &amp;gt;&amp;gt; file_new&lt;BR /&gt;done</description>
      <pubDate>Tue, 05 Jun 2001 14:28:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-insert-a-line-into-a-text-file/m-p/2536518#M899420</guid>
      <dc:creator>Vincenzo Restuccia</dc:creator>
      <dc:date>2001-06-05T14:28:26Z</dc:date>
    </item>
  </channel>
</rss>

