<?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 Adding second line with sed to file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552873#M225236</link>
    <description>Does anyone know how to add two lines of&lt;BR /&gt;text into a file(not end of file) when&lt;BR /&gt;replacing one line with sed.&lt;BR /&gt;&lt;BR /&gt;example:&lt;BR /&gt;&lt;BR /&gt;Look for string in file of "#end":&lt;BR /&gt; &lt;BR /&gt;#end &lt;BR /&gt;&lt;BR /&gt;somewhare in file and add "newline" string plus "#end" string afterwords:&lt;BR /&gt;&lt;BR /&gt;newline&lt;BR /&gt;#end&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It is of course easy to use:&lt;BR /&gt;&lt;BR /&gt;sed s/string1/strings2/&lt;BR /&gt;&lt;BR /&gt;But I just can't get the new line of text added afterwords.&lt;BR /&gt;&lt;BR /&gt;sed s/strings1/strings2\nstring1/    ????&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 26 May 2005 17:38:07 GMT</pubDate>
    <dc:creator>jerry1</dc:creator>
    <dc:date>2005-05-26T17:38:07Z</dc:date>
    <item>
      <title>Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552873#M225236</link>
      <description>Does anyone know how to add two lines of&lt;BR /&gt;text into a file(not end of file) when&lt;BR /&gt;replacing one line with sed.&lt;BR /&gt;&lt;BR /&gt;example:&lt;BR /&gt;&lt;BR /&gt;Look for string in file of "#end":&lt;BR /&gt; &lt;BR /&gt;#end &lt;BR /&gt;&lt;BR /&gt;somewhare in file and add "newline" string plus "#end" string afterwords:&lt;BR /&gt;&lt;BR /&gt;newline&lt;BR /&gt;#end&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It is of course easy to use:&lt;BR /&gt;&lt;BR /&gt;sed s/string1/strings2/&lt;BR /&gt;&lt;BR /&gt;But I just can't get the new line of text added afterwords.&lt;BR /&gt;&lt;BR /&gt;sed s/strings1/strings2\nstring1/    ????&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 26 May 2005 17:38:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552873#M225236</guid>
      <dc:creator>jerry1</dc:creator>
      <dc:date>2005-05-26T17:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552874#M225237</link>
      <description>I found myself in the same conundrum more than once in my life and devised a methodology without getting too much into cryptic sed commands.&lt;BR /&gt;&lt;BR /&gt;I tweak this little script everytime I use it as my needs change, but you can get the basic idea. chop up the file, insert your text and reconstruct it.&lt;BR /&gt;&lt;BR /&gt;Here it goes and hope it helps.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;FILE=File_to_be_edited&lt;BR /&gt;PATTERN="whatever you wish to find"&lt;BR /&gt;&lt;BR /&gt;# find your line number which contains the pattern&lt;BR /&gt;findline=`grep -n "${PATTERN}" $FILE|cut -d: -f1`&lt;BR /&gt;&lt;BR /&gt;# cut and paste whatever is before this line into a header section&lt;BR /&gt;sed -e "${findline},\$d" ${FILE} &amp;gt; /tmp/file_header&lt;BR /&gt;&lt;BR /&gt;# cut and paste whatever is after this line into a footer section&lt;BR /&gt;let f_minus_one=${findline}-1&lt;BR /&gt;sed -e "1,${f_minus_one}d" ${FILE} &amp;gt; /tmp/file_footer&lt;BR /&gt;&lt;BR /&gt;# reconstruct your FILE&lt;BR /&gt;#&lt;BR /&gt;# put the header section first&lt;BR /&gt;cat /tmp/file_header &amp;gt; ${FILE}&lt;BR /&gt;&lt;BR /&gt;# add your insertions&lt;BR /&gt;echo "my inserted line" &amp;gt;&amp;gt; ${FILE}&lt;BR /&gt;echo "another inserted line" &amp;gt;&amp;gt; ${FILE}&lt;BR /&gt;&lt;BR /&gt;# finish off with putting whatever is in the footer section&lt;BR /&gt;cat /tmp/file_footer &amp;gt;&amp;gt; ${FILE}&lt;BR /&gt;</description>
      <pubDate>Thu, 26 May 2005 18:00:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552874#M225237</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-05-26T18:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552875#M225238</link>
      <description>how about something like:&lt;BR /&gt;&lt;BR /&gt;sed '/s1/{h;s/s1/s2/;G;}'</description>
      <pubDate>Thu, 26 May 2005 19:00:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552875#M225238</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-05-26T19:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552876#M225239</link>
      <description>Not sure of the syntax but it works:&lt;BR /&gt;&lt;BR /&gt;sed -e 's/string1/&amp;amp;string2/g'</description>
      <pubDate>Thu, 26 May 2005 23:26:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552876#M225239</guid>
      <dc:creator>Vibhor Kumar Agarwal</dc:creator>
      <dc:date>2005-05-26T23:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552877#M225240</link>
      <description>Is it working as,&lt;BR /&gt;&lt;BR /&gt;sed -e 's/#end/newline\&lt;BR /&gt;#end/g' &lt;FILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;Else you can go with awk as,&lt;BR /&gt;&lt;BR /&gt;awk '{ if ( $0 ~= "#end" ) { printf "newline\n"$0"\n" }}' &lt;FILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;hth.&lt;/FILENAME&gt;&lt;/FILENAME&gt;</description>
      <pubDate>Fri, 27 May 2005 02:05:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552877#M225240</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-05-27T02:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552878#M225241</link>
      <description>Mel, thanks. Good enough.&lt;BR /&gt;&lt;BR /&gt;I could not however get the others to&lt;BR /&gt;work.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# sed  "s/#end/{h;s/#end/test/;G;}" rules.test  &lt;BR /&gt;sed: command garbled: s/#end/{h;s/#end/test/;G;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Not sure if the syntax is right below. $0 - ??&lt;BR /&gt;&lt;BR /&gt;# awk '{ if ($0 ~= "#end" ) { printf "newline\n"$0"\n" }}' rules.test&lt;BR /&gt;awk: syntax error near line 1&lt;BR /&gt;awk: illegal statement near line 1&lt;BR /&gt;awk: syntax error near line 1&lt;BR /&gt;awk: bailing out near line 1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Does not give me a new line for the string&lt;BR /&gt;"test" but it seems to be close. Seems like&lt;BR /&gt;you could put some kind of switch in between&lt;BR /&gt;&amp;amp; and the string "test". &lt;BR /&gt;&lt;BR /&gt;sed  "s/#end/&amp;amp;test/g" rules.test&lt;BR /&gt;&lt;BR /&gt;#endtest&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;------------------------------------&lt;BR /&gt;I tried this one already.&lt;BR /&gt;&lt;BR /&gt;# sed -e "s/#end/test\&lt;BR /&gt;newline/g" rules.test&lt;BR /&gt;                     &lt;BR /&gt;testnewline&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 27 May 2005 08:14:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552878#M225241</guid>
      <dc:creator>jerry1</dc:creator>
      <dc:date>2005-05-27T08:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552879#M225242</link>
      <description>hello Jerry,&lt;BR /&gt;&lt;BR /&gt;in regards to:&lt;BR /&gt;&lt;BR /&gt;I could not however get the others to work.&lt;BR /&gt;# sed "s/#end/{h;s/#end/test/;G;}" rules.test &lt;BR /&gt;sed: command garbled: s/#end/{h;s/#end/test/;G;}&lt;BR /&gt;&lt;BR /&gt;you have the syntax wrong; it should be:&lt;BR /&gt;&lt;BR /&gt;sed '/#end/{h;s/#end/test/;G;}' rules.test&lt;BR /&gt;&lt;BR /&gt;not:&lt;BR /&gt;sed "s/#end/{h;s/#end/test/;G;}" &lt;BR /&gt;aaaaa^, there is no "s" at the begining.</description>
      <pubDate>Fri, 27 May 2005 08:40:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552879#M225242</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-05-27T08:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552880#M225243</link>
      <description>and the awk command would work better as:&lt;BR /&gt;&lt;BR /&gt;awk '{ if ( $0 ~= "#end" ) { &lt;BR /&gt;printf("newline\n%s\n",$0);}}' &lt;FILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;or &lt;BR /&gt;&lt;BR /&gt;awk '/#end/ {printf "newline\n%s\n",$0);}' &lt;FILENAME&gt;&lt;/FILENAME&gt;&lt;/FILENAME&gt;</description>
      <pubDate>Fri, 27 May 2005 08:46:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552880#M225243</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-05-27T08:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552881#M225244</link>
      <description>Jerry,&lt;BR /&gt;&lt;BR /&gt;The sed line Muthukumar showed works interactively, but it hard to do in a script.&lt;BR /&gt;You need that new newline character after the 'text for the new line'.&lt;BR /&gt;&lt;BR /&gt;The awk suggestion needs a little tweak.&lt;BR /&gt;This works for me:&lt;BR /&gt;awk '/^\#end/{print "newline"} {print}' &lt;FILE&gt;&lt;BR /&gt;&lt;BR /&gt;demo below.&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;#cat x&lt;BR /&gt;aap&lt;BR /&gt;end #end&lt;BR /&gt;noot&lt;BR /&gt;#end&lt;BR /&gt;#&lt;BR /&gt;# awk '/^\#end/{print "newline"} {print}' x&lt;BR /&gt;aap&lt;BR /&gt;end #end&lt;BR /&gt;noot&lt;BR /&gt;newline&lt;BR /&gt;#end&lt;BR /&gt;$ sed -e 's/#end/newline2\&lt;BR /&gt;&amp;gt; #end/g' x&lt;BR /&gt;aap&lt;BR /&gt;end newline2&lt;BR /&gt;#end&lt;BR /&gt;noot&lt;BR /&gt;newline2&lt;BR /&gt;#end&lt;BR /&gt;&lt;BR /&gt;&lt;/FILE&gt;</description>
      <pubDate>Fri, 27 May 2005 08:49:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552881#M225244</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-05-27T08:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552882#M225245</link>
      <description>I know how to cheat&lt;BR /&gt;&lt;BR /&gt;Assume your data does have a Carriage Return&lt;BR /&gt;(^M, control M)&lt;BR /&gt;&lt;BR /&gt;sed 's/#end/  XXXX ^M #end/g' |tr "\r" "\n"&lt;BR /&gt;&lt;BR /&gt;You can insert a ^M, using vi by &lt;BR /&gt;Control V and then Control M.&lt;BR /&gt;&lt;BR /&gt;If you know your data NEVER has a certain character like a ~, etc you could use that instead of a control character.&lt;BR /&gt;&lt;BR /&gt;Rory</description>
      <pubDate>Fri, 27 May 2005 10:19:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552882#M225245</guid>
      <dc:creator>Rory R Hammond</dc:creator>
      <dc:date>2005-05-27T10:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Adding second line with sed to file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552883#M225246</link>
      <description>My appologies Curt. Habbit of always&lt;BR /&gt;typing sed s/&lt;BR /&gt;&lt;BR /&gt;They both work.&lt;BR /&gt;Curt you had a typo though in:&lt;BR /&gt;&lt;BR /&gt;awk '/#end/ {printf "newline\n%s\n",$0);}' &lt;FILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;No ")" after 0 and it works.&lt;BR /&gt;&lt;BR /&gt;Hein van den's works also.&lt;BR /&gt;&lt;BR /&gt;Thanks Guys!&lt;BR /&gt;&lt;BR /&gt;&lt;/FILENAME&gt;</description>
      <pubDate>Fri, 27 May 2005 10:48:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/adding-second-line-with-sed-to-file/m-p/3552883#M225246</guid>
      <dc:creator>jerry1</dc:creator>
      <dc:date>2005-05-27T10:48:37Z</dc:date>
    </item>
  </channel>
</rss>

