<?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: Using VI to insert line from bash script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136358#M688744</link>
    <description>Replace X with the correct pattern&lt;BR /&gt;&lt;BR /&gt;$ perl -pi -e'/^X$/ and $_ .= "\n$ENV{Z}\n"' FILE&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
    <pubDate>Mon, 20 Oct 2008 15:02:52 GMT</pubDate>
    <dc:creator>H.Merijn Brand (procura</dc:creator>
    <dc:date>2008-10-20T15:02:52Z</dc:date>
    <item>
      <title>Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136355#M688741</link>
      <description>Dears, &lt;BR /&gt;&lt;BR /&gt;Good day, &lt;BR /&gt;&lt;BR /&gt;I would like to write a sh script that insert a line in a file BUT I keep getting "Input read error" &lt;BR /&gt;&lt;BR /&gt;This is my try : &lt;BR /&gt;&lt;BR /&gt;vi a &amp;lt;&amp;lt; EOF&lt;BR /&gt;:i&lt;BR /&gt;insert&lt;BR /&gt;^[&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Mon, 20 Oct 2008 13:00:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136355#M688741</guid>
      <dc:creator>AZayed</dc:creator>
      <dc:date>2008-10-20T13:00:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136356#M688742</link>
      <description>vi is I suspect, not the tool for this job...more likely is that some other tool such as sed will do what you require, but more information is required first... where does the line get inserted in the file - at the start? at the end? somewhere else? Please describe you problem in a little more detail.&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Duncan</description>
      <pubDate>Mon, 20 Oct 2008 13:24:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136356#M688742</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2008-10-20T13:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136357#M688743</link>
      <description>Hi, &lt;BR /&gt;&lt;BR /&gt;Thanks for reply, &lt;BR /&gt;&lt;BR /&gt;I have a file containing certain value X. About this value in four lines there is value Y I want to take Y and put instead X. And shift the lines one line below. &lt;BR /&gt;&lt;BR /&gt;For Example : &lt;BR /&gt;&lt;BR /&gt;1 junk data &lt;BR /&gt;2 junk data &lt;BR /&gt;3 Y &lt;BR /&gt;4 junk data &lt;BR /&gt;5 junk data &lt;BR /&gt;6 junk data &lt;BR /&gt;7 X &lt;BR /&gt;8 junk data &lt;BR /&gt;&lt;BR /&gt;I want to do the following : &lt;BR /&gt;&lt;BR /&gt;1 junk data &lt;BR /&gt;2 junk data &lt;BR /&gt;3 Y &lt;BR /&gt;4 junk data &lt;BR /&gt;5 junk data &lt;BR /&gt;6 junk data &lt;BR /&gt;7 Y &lt;BR /&gt;8 OLD X Updated &lt;BR /&gt;9 junk data &lt;BR /&gt;&lt;BR /&gt;So I wrote the following as part of my shell script : "I have Y value in variable Z" &lt;BR /&gt;&lt;BR /&gt;vi FILE &amp;lt;&amp;lt; EOF &lt;BR /&gt;:7&lt;BR /&gt;:O &lt;BR /&gt;$Z &lt;BR /&gt;^[ &lt;BR /&gt;:j &lt;BR /&gt;:xx&lt;BR /&gt;:wq! &lt;BR /&gt;EOF &lt;BR /&gt;&lt;BR /&gt;----------------- &lt;BR /&gt;&lt;BR /&gt;This is what I want. but it seams not working even if I want only to do this : &lt;BR /&gt;&lt;BR /&gt;vi FILE &amp;lt;&amp;lt; EOF &lt;BR /&gt;:7&lt;BR /&gt;:O &lt;BR /&gt;$Z &lt;BR /&gt;^[ &lt;BR /&gt;:ZZ&lt;BR /&gt;EOF &lt;BR /&gt;&lt;BR /&gt;Any help? &lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Mon, 20 Oct 2008 14:55:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136357#M688743</guid>
      <dc:creator>AZayed</dc:creator>
      <dc:date>2008-10-20T14:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136358#M688744</link>
      <description>Replace X with the correct pattern&lt;BR /&gt;&lt;BR /&gt;$ perl -pi -e'/^X$/ and $_ .= "\n$ENV{Z}\n"' FILE&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Mon, 20 Oct 2008 15:02:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136358#M688744</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2008-10-20T15:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136359#M688745</link>
      <description>Here is an example solution using AWK.&lt;BR /&gt;&lt;BR /&gt;$ awk '/X/{print line[(NR-4)%10]; $0 = "old " $0} {line[NR%10] = $0; print}' x&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;In slow motion:&lt;BR /&gt;&lt;BR /&gt;/X/ {  # if you see a line marked 'X' then&lt;BR /&gt;print line[(NR-4)%10]; # Pick up 4 lines ago from secret stash, and&lt;BR /&gt;$0 = "old " $0}  # munge current line&lt;BR /&gt;&lt;BR /&gt;{      # for each line&lt;BR /&gt;line[NR%10] = $0; # put in stash (circular buffer), and&lt;BR /&gt;print}  # print current line (may be modified)&lt;BR /&gt;' x     # input from a file called x&lt;BR /&gt;&lt;BR /&gt;I used a 10 element circular buffer using a MODULUS function just for grins, to make clear where the '4 lines above' goes.&lt;BR /&gt;Using 5 elements would of course be enough.&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Mon, 20 Oct 2008 17:16:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136359#M688745</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-10-20T17:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136360#M688746</link>
      <description>Hi folks, &lt;BR /&gt;&lt;BR /&gt;I have to try them tomorrow. I have only one point to mention that X value it's not unique, it will be repeated over and over in the file. &lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Mon, 20 Oct 2008 17:21:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136360#M688746</guid>
      <dc:creator>AZayed</dc:creator>
      <dc:date>2008-10-20T17:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136361#M688747</link>
      <description>My awk solution will replace any line with the X with the line 4 lines earlier to that occurance of X, and add a line with the munged current X line.&lt;BR /&gt;&lt;BR /&gt;Is that what was intended, Did you want to pick up only a first 'Y' and repeat that?&lt;BR /&gt;&lt;BR /&gt;Of course you should replace 'X' Regular Expression which does nto generate false positive. Anchoring the string often helps a lot with that: For example /^X/ to recognize X only when at the very start of a line.&lt;BR /&gt;&lt;BR /&gt;To get better help, please try to explain more clearly how to recognize the lines with 'X' and 'Y'.&lt;BR /&gt;By contents?&lt;BR /&gt;By contents of lines around them?&lt;BR /&gt;By (relative) record number?&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Mon, 20 Oct 2008 17:37:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136361#M688747</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-10-20T17:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136362#M688748</link>
      <description>if it is repeated, do you want everey X replaced? Both Hein's awk solution and my perl will do that.&lt;BR /&gt;&lt;BR /&gt;If you want only the first, you need a guard&lt;BR /&gt;&lt;BR /&gt;$ perl -pi -e'/^X$/&amp;amp;&amp;amp;$ENV{Z}and$_.="\n".delete$ENV{Z}."\n"' FILE&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn [ who loves dirty trickery and one-liners ]</description>
      <pubDate>Mon, 20 Oct 2008 19:59:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136362#M688748</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2008-10-20T19:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136363#M688749</link>
      <description>Hi, &lt;BR /&gt;&lt;BR /&gt;Thanks for reply, I'm sorry but the hole concept changed today, &lt;BR /&gt;&lt;BR /&gt;this is a real data &lt;BR /&gt;,10:1&lt;BR /&gt;,11:1&lt;BR /&gt;,14:1001&lt;BR /&gt;17,10:1&lt;BR /&gt;,11:0&lt;BR /&gt;,12:0&lt;BR /&gt;&lt;BR /&gt;I want to replace each "17,10:1" to "17,9:1/E" and insert a new line under it with a value ",10:1" &lt;BR /&gt;&lt;BR /&gt;So, how can I do this with awk ? &lt;BR /&gt;&lt;BR /&gt;Regards,</description>
      <pubDate>Tue, 21 Oct 2008 09:12:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136363#M688749</guid>
      <dc:creator>AZayed</dc:creator>
      <dc:date>2008-10-21T09:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136364#M688750</link>
      <description>Hi, &lt;BR /&gt;&lt;BR /&gt;I wrote this in sed, I have to put it in sh script. &lt;BR /&gt;&lt;BR /&gt;sed '&lt;BR /&gt;/^17,10:1$/ a\&lt;BR /&gt;,10:1&lt;BR /&gt;s#^17,10:1$#17,9:5/E#g'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It's work, Any more powerful Ideas ?</description>
      <pubDate>Tue, 21 Oct 2008 09:46:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136364#M688750</guid>
      <dc:creator>AZayed</dc:creator>
      <dc:date>2008-10-21T09:46:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136365#M688751</link>
      <description>&amp;gt;&amp;gt; I want to replace each "17,10:1" to "17,9:1/E" and insert a new line under it with a value ",10:1" &lt;BR /&gt;&amp;gt;&amp;gt; So, how can I do this with awk ? &lt;BR /&gt;&lt;BR /&gt;yes, but WHY?&lt;BR /&gt;&lt;BR /&gt; awk '/^17,10:1/ {gsub (/,/, ",9.5/E\n,")} {print} ' x&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; It's work, Any more powerful Ideas ? &lt;BR /&gt; &lt;BR /&gt;Only if you describe in a powerful way where the 17 and the 9.1 (9.5) and such come from. &lt;BR /&gt;Are they really just fixed strings, always the same? That is a totally boring case. Just pick a solution and be happy.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Oct 2008 10:44:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136365#M688751</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-10-21T10:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136366#M688752</link>
      <description>Hi Hein, &lt;BR /&gt;&lt;BR /&gt;My customer changed his idea so I had to change my work. And yes, it's easy one. &lt;BR /&gt;&lt;BR /&gt;But in your awk command, you didn't insert ",10:1" value. &lt;BR /&gt;&lt;BR /&gt;Last thing before I close this case, do you recommend a useful awk and sed from personal experiences? &lt;BR /&gt;&lt;BR /&gt;Thanks :)</description>
      <pubDate>Tue, 21 Oct 2008 11:06:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136366#M688752</guid>
      <dc:creator>AZayed</dc:creator>
      <dc:date>2008-10-21T11:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136367#M688753</link>
      <description>Hi Hein, &lt;BR /&gt;&lt;BR /&gt;It seems your line working great. although, I didn't notice that you wrote ",10:1" in your line. But your awk line doing what I want do do. It's amazing :) &lt;BR /&gt;&lt;BR /&gt;I want to learn how to use awk because this line is more powerful than complex bash script. &lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Tue, 21 Oct 2008 11:32:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136367#M688753</guid>
      <dc:creator>AZayed</dc:creator>
      <dc:date>2008-10-21T11:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136368#M688754</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;If you want to start with 'awk' you could use this free, but excellent guide:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.gnu.org/software/gawk/manual/gawk.html" target="_blank"&gt;http://www.gnu.org/software/gawk/manual/gawk.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Be aware that the GNU variant is a bit more powerful than HP's or AIX's standard.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 21 Oct 2008 11:38:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136368#M688754</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-10-21T11:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136369#M688755</link>
      <description>Thanks JRF, &lt;BR /&gt;&lt;BR /&gt;Thanks folks for your support. &lt;BR /&gt;&lt;BR /&gt;Have a nice day.</description>
      <pubDate>Tue, 21 Oct 2008 11:50:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136369#M688755</guid>
      <dc:creator>AZayed</dc:creator>
      <dc:date>2008-10-21T11:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136370#M688756</link>
      <description>Yes, &lt;BR /&gt;&lt;BR /&gt;It's awk command. It's powerful. &lt;BR /&gt;&lt;BR /&gt;awk '/^17,10:1$/ { gsub (/,/, ",9:5/E\n,") } { print }'</description>
      <pubDate>Tue, 21 Oct 2008 11:52:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136370#M688756</guid>
      <dc:creator>AZayed</dc:creator>
      <dc:date>2008-10-21T11:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136371#M688757</link>
      <description>&amp;gt;&amp;gt; It seems your line working great. although, I didn't notice that you wrote ",10:1" in your line. But your awk line doing what I want do do. It's amazing :) &lt;BR /&gt;&lt;BR /&gt;I did't write ,10:1. That was already there :-).&lt;BR /&gt;I just stuck a new-line ( \n ) in front of it.&lt;BR /&gt;&lt;BR /&gt;I wrote my solution in anticipation of future, other needs. That's was seperates solutions from hacks. &lt;BR /&gt;My assumption was that you did not want "10:1" but "whatever was on the old line after the comma"... which happens to be 10:1 for now.&lt;BR /&gt;Similar for the 17. I left the value itself on the line, using it only as a simple regular expression untill you explained better where the 17 came from.&lt;BR /&gt;I only replaced the comma, not the values.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;$ awk '/^[0-9]+,/ {gsub (/,/, ",9.5/E\n,")} {print} ' x&lt;BR /&gt;&lt;BR /&gt;... no 17, no 10, and yet...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; I want to learn how to use awk because this line is more powerful than complex bash script. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I was hoping that, and that's why I providede the blow-by-blow breakdown in my first example. Try to follow that!&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Oct 2008 12:44:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136371#M688757</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2008-10-21T12:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using VI to insert line from bash script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136372#M688758</link>
      <description>As Duncan said, you can't use vi.  You can use sed(1), awk(1), perl(1), ed(1) or ex(1).&lt;BR /&gt;&lt;BR /&gt;Your example above would be:&lt;BR /&gt;ex a &amp;lt;&amp;lt; EOF&lt;BR /&gt;i&lt;BR /&gt;insert data&lt;BR /&gt;.&lt;BR /&gt;wq&lt;BR /&gt;EOF</description>
      <pubDate>Tue, 21 Oct 2008 22:31:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-vi-to-insert-line-from-bash-script/m-p/5136372#M688758</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-10-21T22:31:00Z</dc:date>
    </item>
  </channel>
</rss>

