<?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: shell script problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983057#M122453</link>
    <description>the best way would be to make your edits to a temporary file using sed, awk, perl, or the shell.  Examine the changes for correctness then copy your changes to your original file.&lt;BR /&gt;&lt;BR /&gt;now if you have to edit your file in place, your pretty much limited to using perl or the ex editor.  Perl definitely has superior capabilities.&lt;BR /&gt;&lt;BR /&gt;there already is a solution for perl, so i'll give you a couple using ex.&lt;BR /&gt;&lt;BR /&gt;one using mulitiple edits&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;line="end message&lt;BR /&gt;start message&lt;BR /&gt;."&lt;BR /&gt;&lt;BR /&gt;x=$(wc -l textfile | awk '{print $1;exit;}')&lt;BR /&gt;x=$(( $x/10 ))&lt;BR /&gt;&lt;BR /&gt;y=10&lt;BR /&gt;if (( $x &amp;gt; 1 )) ;then&lt;BR /&gt;ex -s textfile &amp;lt;&amp;lt;-EOF&lt;BR /&gt;${y}a&lt;BR /&gt;$line&lt;BR /&gt;wq&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;a=1&lt;BR /&gt;while (( $x &amp;gt; $a ))&lt;BR /&gt;do&lt;BR /&gt;y=$(( $y+12 ))&lt;BR /&gt;ex -s textfile &amp;lt;&amp;lt;-EOF&lt;BR /&gt;${y}a&lt;BR /&gt;$line&lt;BR /&gt;wq&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;a=$(( $a+1 ))&lt;BR /&gt;done&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;or you can write the editor command to a tmp file and edit the file just once&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;line="end message&lt;BR /&gt;start message&lt;BR /&gt;."&lt;BR /&gt;&lt;BR /&gt;x=$(wc -l textfile | awk '{print $1;exit;}')&lt;BR /&gt;x=$(( $x/10 ))&lt;BR /&gt;&lt;BR /&gt;if (( $x &amp;gt; 1 )) ;then&lt;BR /&gt;print "10a|$line" &amp;gt; tmpfile&lt;BR /&gt;a=1&lt;BR /&gt;while (( $x &amp;gt; $a ))&lt;BR /&gt;do&lt;BR /&gt;print ".+10a|$line" &amp;gt;&amp;gt; tmpfile&lt;BR /&gt;a=$(( $a+1 ))&lt;BR /&gt;done&lt;BR /&gt;ex -s textfile &amp;lt;&amp;lt;-EOF&lt;BR /&gt;so tmpfile&lt;BR /&gt;wq&lt;BR /&gt;EOF&lt;BR /&gt;fi&lt;BR /&gt;rm tmpfile&lt;BR /&gt;&lt;BR /&gt;both do what you want, but I wouldn't call them good solutions</description>
    <pubDate>Wed, 28 May 2003 14:51:29 GMT</pubDate>
    <dc:creator>curt larson_1</dc:creator>
    <dc:date>2003-05-28T14:51:29Z</dc:date>
    <item>
      <title>shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983052#M122448</link>
      <description>Hi.&lt;BR /&gt;&lt;BR /&gt;Anybody could be help ?&lt;BR /&gt;&lt;BR /&gt;if I have text file as below&lt;BR /&gt;&lt;BR /&gt;line 1&lt;BR /&gt;line 2&lt;BR /&gt;line 3&lt;BR /&gt;line 4&lt;BR /&gt;line 5&lt;BR /&gt;line 6&lt;BR /&gt;line 7&lt;BR /&gt;line 8&lt;BR /&gt;line 9&lt;BR /&gt;line 10&lt;BR /&gt;line 11&lt;BR /&gt;line 12&lt;BR /&gt;line 13&lt;BR /&gt;line 14&lt;BR /&gt;line 15&lt;BR /&gt;line 16&lt;BR /&gt;line 17&lt;BR /&gt;line 18&lt;BR /&gt;line 19&lt;BR /&gt;line 20&lt;BR /&gt;line 21&lt;BR /&gt;line 22&lt;BR /&gt;&lt;BR /&gt;I want to insert messages between very 10 lines for example as below&lt;BR /&gt;&lt;BR /&gt;start message&lt;BR /&gt;line 1 &lt;BR /&gt;line 2&lt;BR /&gt;...&lt;BR /&gt;line 10&lt;BR /&gt;end message&lt;BR /&gt;start message&lt;BR /&gt;line 11&lt;BR /&gt;line 12&lt;BR /&gt;...&lt;BR /&gt;line 20&lt;BR /&gt;end message&lt;BR /&gt;start message&lt;BR /&gt;line 21&lt;BR /&gt;line 22&lt;BR /&gt;end message&lt;BR /&gt;&lt;BR /&gt;How can I write shell script without redirect to file (read and insert in memory) ?&lt;BR /&gt;&lt;BR /&gt;Many thanks&lt;BR /&gt;Wiboon.</description>
      <pubDate>Wed, 28 May 2003 07:45:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983052#M122448</guid>
      <dc:creator>Wiboon Tanakitpaisal_1</dc:creator>
      <dc:date>2003-05-28T07:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983053#M122449</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;This shell script sends its' output to stdout not a file - is that what you mean?&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;i=0&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;  echo $LINE&lt;BR /&gt;  i=$((i+1))&lt;BR /&gt;  if [[ i -eq 10 ]]&lt;BR /&gt;  then&lt;BR /&gt;    echo "end message"&lt;BR /&gt;    echo "start message"&lt;BR /&gt;    i=0&lt;BR /&gt;  fi&lt;BR /&gt;done &lt;YOUR_TEXT_FILE&gt;&lt;/YOUR_TEXT_FILE&gt;&lt;BR /&gt;regards,&lt;BR /&gt;&lt;BR /&gt;Darren.</description>
      <pubDate>Wed, 28 May 2003 08:08:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983053#M122449</guid>
      <dc:creator>Darren Prior</dc:creator>
      <dc:date>2003-05-28T08:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983054#M122450</link>
      <description>Hi,&lt;BR /&gt;I think he mean editing the the file direct without using any temporary file. This is possible with perl or you have to write a C program.</description>
      <pubDate>Wed, 28 May 2003 08:13:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983054#M122450</guid>
      <dc:creator>Leif Halvarsson_2</dc:creator>
      <dc:date>2003-05-28T08:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983055#M122451</link>
      <description>l1:/tmp 107 &amp;gt; perl -pe'$.%10 or$_.="start msg\nend msg\n"' xx.txt&lt;BR /&gt;line 1&lt;BR /&gt;line 2&lt;BR /&gt;line 3&lt;BR /&gt;line 4&lt;BR /&gt;line 5&lt;BR /&gt;line 6&lt;BR /&gt;line 7&lt;BR /&gt;line 8&lt;BR /&gt;line 9&lt;BR /&gt;line 10&lt;BR /&gt;start msg&lt;BR /&gt;end msg&lt;BR /&gt;line 11&lt;BR /&gt;line 12&lt;BR /&gt;line 13&lt;BR /&gt;line 14&lt;BR /&gt;line 15&lt;BR /&gt;line 16&lt;BR /&gt;line 17&lt;BR /&gt;line 18&lt;BR /&gt;line 19&lt;BR /&gt;line 20&lt;BR /&gt;start msg&lt;BR /&gt;end msg&lt;BR /&gt;line 21&lt;BR /&gt;&lt;BR /&gt;inline editing possible.&lt;BR /&gt;&lt;BR /&gt;l1:/tmp 107 &amp;gt; perl -pi -e'$.%10 or$_.="start msg\nend msg\n"' xx.txt&lt;BR /&gt;&lt;BR /&gt;Enjoy, have FUN! H.Merijn&lt;BR /&gt;</description>
      <pubDate>Wed, 28 May 2003 08:28:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983055#M122451</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-05-28T08:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983056#M122452</link>
      <description>sh-posix solution.&lt;BR /&gt;&lt;BR /&gt;Put this in a file called test.sh&lt;BR /&gt;#########################&lt;BR /&gt;&lt;BR /&gt;#!/sbin/sh&lt;BR /&gt;COUNT=1&lt;BR /&gt;while read TUTTO&lt;BR /&gt;do&lt;BR /&gt;        if (( $COUNT == 1))&lt;BR /&gt;        then&lt;BR /&gt;        echo START MESSAGE&lt;BR /&gt;        fi&lt;BR /&gt;        echo $TUTTO&lt;BR /&gt;        let COUNT=COUNT+1&lt;BR /&gt;        if (( $COUNT == 11))&lt;BR /&gt;        then&lt;BR /&gt;        echo STOP MESSAGE&lt;BR /&gt;        let COUNT=1&lt;BR /&gt;        fi&lt;BR /&gt;done&lt;BR /&gt;if (( $COUNT != 1))&lt;BR /&gt;then&lt;BR /&gt;echo STOP MESSAGE&lt;BR /&gt;fi&lt;BR /&gt;#################&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Once done:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;cat yourfile.txt | test.sh &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;here you go.&lt;BR /&gt;&lt;BR /&gt;   Massimo&lt;BR /&gt;</description>
      <pubDate>Wed, 28 May 2003 08:39:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983056#M122452</guid>
      <dc:creator>Massimo Bianchi</dc:creator>
      <dc:date>2003-05-28T08:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983057#M122453</link>
      <description>the best way would be to make your edits to a temporary file using sed, awk, perl, or the shell.  Examine the changes for correctness then copy your changes to your original file.&lt;BR /&gt;&lt;BR /&gt;now if you have to edit your file in place, your pretty much limited to using perl or the ex editor.  Perl definitely has superior capabilities.&lt;BR /&gt;&lt;BR /&gt;there already is a solution for perl, so i'll give you a couple using ex.&lt;BR /&gt;&lt;BR /&gt;one using mulitiple edits&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;line="end message&lt;BR /&gt;start message&lt;BR /&gt;."&lt;BR /&gt;&lt;BR /&gt;x=$(wc -l textfile | awk '{print $1;exit;}')&lt;BR /&gt;x=$(( $x/10 ))&lt;BR /&gt;&lt;BR /&gt;y=10&lt;BR /&gt;if (( $x &amp;gt; 1 )) ;then&lt;BR /&gt;ex -s textfile &amp;lt;&amp;lt;-EOF&lt;BR /&gt;${y}a&lt;BR /&gt;$line&lt;BR /&gt;wq&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;a=1&lt;BR /&gt;while (( $x &amp;gt; $a ))&lt;BR /&gt;do&lt;BR /&gt;y=$(( $y+12 ))&lt;BR /&gt;ex -s textfile &amp;lt;&amp;lt;-EOF&lt;BR /&gt;${y}a&lt;BR /&gt;$line&lt;BR /&gt;wq&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;a=$(( $a+1 ))&lt;BR /&gt;done&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;or you can write the editor command to a tmp file and edit the file just once&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;line="end message&lt;BR /&gt;start message&lt;BR /&gt;."&lt;BR /&gt;&lt;BR /&gt;x=$(wc -l textfile | awk '{print $1;exit;}')&lt;BR /&gt;x=$(( $x/10 ))&lt;BR /&gt;&lt;BR /&gt;if (( $x &amp;gt; 1 )) ;then&lt;BR /&gt;print "10a|$line" &amp;gt; tmpfile&lt;BR /&gt;a=1&lt;BR /&gt;while (( $x &amp;gt; $a ))&lt;BR /&gt;do&lt;BR /&gt;print ".+10a|$line" &amp;gt;&amp;gt; tmpfile&lt;BR /&gt;a=$(( $a+1 ))&lt;BR /&gt;done&lt;BR /&gt;ex -s textfile &amp;lt;&amp;lt;-EOF&lt;BR /&gt;so tmpfile&lt;BR /&gt;wq&lt;BR /&gt;EOF&lt;BR /&gt;fi&lt;BR /&gt;rm tmpfile&lt;BR /&gt;&lt;BR /&gt;both do what you want, but I wouldn't call them good solutions</description>
      <pubDate>Wed, 28 May 2003 14:51:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983057#M122453</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-05-28T14:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: shell script problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983058#M122454</link>
      <description>With PERL?&lt;BR /&gt;&lt;BR /&gt;perl -ne 'print "START\n" if $.%10==1; print; print "END\n" if $.%10==0;' &amp;lt; file&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 29 May 2003 23:27:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-problem/m-p/2983058#M122454</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2003-05-29T23:27:57Z</dc:date>
    </item>
  </channel>
</rss>

