<?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: Replace two lines with one using AWK in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/replace-two-lines-with-one-using-awk/m-p/3459062#M15809</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;sed  -e 's/#ifdef ABC//g' -e 's/#123456/# Test/g' yourfilename&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;NiCK</description>
    <pubDate>Mon, 10 Jan 2005 02:30:45 GMT</pubDate>
    <dc:creator>NiCK_76</dc:creator>
    <dc:date>2005-01-10T02:30:45Z</dc:date>
    <item>
      <title>Replace two lines with one using AWK</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-two-lines-with-one-using-awk/m-p/3459061#M15808</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I need to replace two lines with one. I tried SED but looks like SED does not accept Ctrl chars as input (eg. linefeed) as required for replacing the two lines.&lt;BR /&gt;&lt;BR /&gt;I need to scan text files and replace the following:&lt;BR /&gt;&lt;BR /&gt;#ifdef ABC&lt;BR /&gt;#123456&lt;BR /&gt;&lt;BR /&gt;with &lt;BR /&gt;&lt;BR /&gt;# Test&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;There is a carriage return between the #ifdef and the #123456.&lt;BR /&gt;&lt;BR /&gt;Have tried with awk without any luck - can someone suggest how to do this.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;BR /&gt;JUP&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Jan 2005 01:46:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-two-lines-with-one-using-awk/m-p/3459061#M15808</guid>
      <dc:creator>JUP</dc:creator>
      <dc:date>2005-01-10T01:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two lines with one using AWK</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-two-lines-with-one-using-awk/m-p/3459062#M15809</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;sed  -e 's/#ifdef ABC//g' -e 's/#123456/# Test/g' yourfilename&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;NiCK</description>
      <pubDate>Mon, 10 Jan 2005 02:30:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-two-lines-with-one-using-awk/m-p/3459062#M15809</guid>
      <dc:creator>NiCK_76</dc:creator>
      <dc:date>2005-01-10T02:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two lines with one using AWK</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-two-lines-with-one-using-awk/m-p/3459063#M15810</link>
      <description>Thanks Nick&lt;BR /&gt;&lt;BR /&gt;however your SED command leaves a blank line in the file. In total I wish to replace 4 lines with 1 so I will have 3 blank lines.&lt;BR /&gt;&lt;BR /&gt;The only way to do this is with AWK - I have come up with this command but its not working. It is:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;awk '{gsub("#ifdef ABC"\r\n#123456, "# Test"); print $0}' file.h &amp;gt; file.out&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Does anyone know whats going wrong here ?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Jan 2005 17:07:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-two-lines-with-one-using-awk/m-p/3459063#M15810</guid>
      <dc:creator>JUP</dc:creator>
      <dc:date>2005-01-10T17:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two lines with one using AWK</title>
      <link>https://community.hpe.com/t5/operating-system-linux/replace-two-lines-with-one-using-awk/m-p/3459064#M15811</link>
      <description>Awk is literally 'line-by-line'.  It can't pattern match over multiple lines.&lt;BR /&gt;&lt;BR /&gt;Perl can (although in my quick tests, I couldn't get it to work (phooey)), so this leaves doing it the hard way.&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;END {&lt;BR /&gt;print THIS&lt;BR /&gt;}&lt;BR /&gt;{&lt;BR /&gt;LAST=THIS&lt;BR /&gt;THIS=$0&lt;BR /&gt;if (SKIP == 1) {&lt;BR /&gt;SKIP=0&lt;BR /&gt;next&lt;BR /&gt;}&lt;BR /&gt;if ((LAST == "#ifdef ABC") &amp;amp;&amp;amp; (THIS == "#123456")) {&lt;BR /&gt;print "#Test"&lt;BR /&gt;SKIP=1&lt;BR /&gt;} else {&lt;BR /&gt;print LAST&lt;BR /&gt;}&lt;BR /&gt;}' &amp;lt; yourfile&lt;BR /&gt;&lt;BR /&gt;I'm sure there's a neater, shorter way out there though.</description>
      <pubDate>Mon, 10 Jan 2005 20:56:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/replace-two-lines-with-one-using-awk/m-p/3459064#M15811</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2005-01-10T20:56:20Z</dc:date>
    </item>
  </channel>
</rss>

