<?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: Delete last two lines in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365691#M867362</link>
    <description>Parmy,&lt;BR /&gt;&lt;BR /&gt;Use "sed -e '$d' my_file |sed -e '$d'"&lt;BR /&gt;&lt;BR /&gt;that should do it.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
    <pubDate>Thu, 26 Aug 2004 06:21:31 GMT</pubDate>
    <dc:creator>Pete Randall</dc:creator>
    <dc:date>2004-08-26T06:21:31Z</dc:date>
    <item>
      <title>Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365690#M867361</link>
      <description>Hi,&lt;BR /&gt;  I have a file in which I don't need the last two lines. How can run a command to achieve this?&lt;BR /&gt;&lt;BR /&gt;I have a work around for my collegue but he is not happy with it.&lt;BR /&gt;&lt;BR /&gt;sed '$d' my_file | sed '$d'&lt;BR /&gt;&lt;BR /&gt;I am expecting some thing like&lt;BR /&gt;&lt;BR /&gt;sed -e '$d' -e '$d' my_file.&lt;BR /&gt;&lt;BR /&gt;Please help us.&lt;BR /&gt;Parmy</description>
      <pubDate>Thu, 26 Aug 2004 06:10:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365690#M867361</guid>
      <dc:creator>parmy_4</dc:creator>
      <dc:date>2004-08-26T06:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365691#M867362</link>
      <description>Parmy,&lt;BR /&gt;&lt;BR /&gt;Use "sed -e '$d' my_file |sed -e '$d'"&lt;BR /&gt;&lt;BR /&gt;that should do it.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete</description>
      <pubDate>Thu, 26 Aug 2004 06:21:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365691#M867362</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2004-08-26T06:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365692#M867363</link>
      <description>vi my_file&amp;lt;&lt;EOF&gt;&lt;/EOF&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Thu, 26 Aug 2004 06:23:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365692#M867363</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2004-08-26T06:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365693#M867364</link>
      <description>with vi cmd&lt;BR /&gt;vi +$ my_file&amp;lt;&lt;EOP&gt;&lt;/EOP&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Thu, 26 Aug 2004 06:32:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365693#M867364</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-08-26T06:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365694#M867365</link>
      <description>Another way:&lt;BR /&gt;&lt;BR /&gt;expr `wc -l my_file | cut -d" " -f1` - 2 | xargs echo | sed -e "s/^/head -/" -e "s/$/ my_file/" | sh &amp;gt; new_my_file&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Thu, 26 Aug 2004 06:57:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365694#M867365</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2004-08-26T06:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365695#M867366</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I think this works (at least it seems so on my screen):&lt;BR /&gt;&lt;BR /&gt;# tail -2 &lt;FILE&gt; | comm -23 &lt;FILE&gt; -&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;&lt;/FILE&gt;&lt;/FILE&gt;</description>
      <pubDate>Thu, 26 Aug 2004 07:00:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365695#M867366</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2004-08-26T07:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365696#M867367</link>
      <description>awk solution :&lt;BR /&gt;awk -v nb=$(wc -l my_file | cut -f1 -d" ") '{if(NR&amp;gt;(nb - 2)) exit; print}' my_file&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Jean-Luc</description>
      <pubDate>Thu, 26 Aug 2004 07:21:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365696#M867367</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2004-08-26T07:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365697#M867368</link>
      <description>A possible solution:&lt;BR /&gt;&lt;BR /&gt;head $(wc -l my_file | awk '{print "-" $1 - 2}') my_file&lt;BR /&gt;&lt;BR /&gt;In vi you can use the command:&lt;BR /&gt;$-1,$d&lt;BR /&gt;to delete the last two lines. Should work in ed too.&lt;BR /&gt;&lt;BR /&gt;Or a complete awk solution:&lt;BR /&gt;awk '{ if (NR &amp;gt; 2) { print prev2  } prev2=prev1;prev1=$0}' &amp;lt; my_file</description>
      <pubDate>Thu, 26 Aug 2004 07:27:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365697#M867368</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-08-26T07:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365698#M867369</link>
      <description>Hi &lt;BR /&gt;This works ..but don't know you like it or not.&lt;BR /&gt;&lt;BR /&gt;# let A=`cat file1 | wc -l`-2 &lt;BR /&gt;# head -$A file1 &amp;gt;file2&lt;BR /&gt;&lt;BR /&gt;That works.&lt;BR /&gt;Regards,&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Aug 2004 07:42:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365698#M867369</guid>
      <dc:creator>Bharat Katkar</dc:creator>
      <dc:date>2004-08-26T07:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365699#M867370</link>
      <description>hi Parmy,&lt;BR /&gt;&lt;BR /&gt;I have no HP-UX where to try it but on Linux&lt;BR /&gt;exists the tac command (opposit to cat)&lt;BR /&gt;&lt;BR /&gt;so maybe the following row will help you&lt;BR /&gt;&lt;BR /&gt;tac file | sed '1,2d' | tac | tee file1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;br Jan</description>
      <pubDate>Thu, 26 Aug 2004 08:03:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365699#M867370</guid>
      <dc:creator>Jan Sladky</dc:creator>
      <dc:date>2004-08-26T08:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365700#M867371</link>
      <description>Here is a perl one-liner that only requires one pass through the file.&lt;BR /&gt; &lt;BR /&gt;perl -ne 'push(@last2,$_); if (scalar @last2 &amp;gt; 2) { print shift @last2}'&lt;BR /&gt; &lt;BR /&gt;By pushing each line onto a stack this script will not print the last 2 lines.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 26 Aug 2004 08:56:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365700#M867371</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-08-26T08:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365701#M867372</link>
      <description>Parmy,&lt;BR /&gt; &lt;BR /&gt;Assigning points to indicate which solution you think works the best is what helps the forum help others...&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 26 Aug 2004 09:00:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365701#M867372</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-08-26T09:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365702#M867373</link>
      <description>cat $file | sed '1,2d'</description>
      <pubDate>Thu, 26 Aug 2004 09:13:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365702#M867373</guid>
      <dc:creator>Rick Garland</dc:creator>
      <dc:date>2004-08-26T09:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365703#M867374</link>
      <description>&lt;BR /&gt;Here is a one-pass in awk which does no create a temp file.&lt;BR /&gt;It uses a 'circular buffer' of the target  'missing line' count 'L'.&lt;BR /&gt;This is done with an array 'line' indexed by the current record number (NR) modulus that L.&lt;BR /&gt;You provide a desired value for L as argument.&lt;BR /&gt;We start printing from the array only after L lines have come by, 'falling behind' by L lines.&lt;BR /&gt;&lt;BR /&gt;Sounds tricky? Here is the 'one line' code:&lt;BR /&gt;&lt;BR /&gt;awk -vL=2 '{if(NR&amp;gt;L){print line[(NR-L)%L];line[NR%L]=$0}}' your-file&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Thu, 26 Aug 2004 09:15:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365703#M867374</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-26T09:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365704#M867375</link>
      <description>Hein, your solution is a variant of my awk solution... but my mathematic mind says you need to remove the -L in your solution. It does nothing in the end... since (NR-L)%L equals NR%L.&lt;BR /&gt;And you have a closing curly bracket wrong, resulting in missing the first lines...&lt;BR /&gt;&lt;BR /&gt;So the right solution would be:&lt;BR /&gt;&lt;BR /&gt;awk -vL=2 '{if(NR&amp;gt;L){print line[NR%L];}line[NR%L]=$0}' my_file</description>
      <pubDate>Fri, 27 Aug 2004 01:13:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365704#M867375</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-08-27T01:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365705#M867376</link>
      <description>Strange point assignment... I've tested the highest rated solution, but it doesn't seem to work. At least nog on the /etc/passwd files I have on Linux and HP-UX... But it could be me...</description>
      <pubDate>Fri, 27 Aug 2004 01:18:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365705#M867376</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-08-27T01:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365706#M867377</link>
      <description>It looks like Parmy is taking it very lightly and on the contrary all the responders are struggling to be as perfect as possible..&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Aug 2004 02:23:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365706#M867377</guid>
      <dc:creator>Bharat Katkar</dc:creator>
      <dc:date>2004-08-27T02:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Delete last two lines</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365707#M867378</link>
      <description>Elmar&amp;gt; Hein, your solution is a variant of my awk solution... &lt;BR /&gt;&lt;BR /&gt;Ayup, just a touch more general purpose. I had missed the awk part of your solution.&lt;BR /&gt;&lt;BR /&gt;Elmar&amp;gt; but my mathematic mind says you need to remove the -L in your solution.&lt;BR /&gt;&lt;BR /&gt;Ayup, a simplication I overlooked this time.&lt;BR /&gt;&lt;BR /&gt;Elmar&amp;gt; It does nothing in the end... since (NR-L)%L equals NR%L.&lt;BR /&gt;&lt;BR /&gt;Ayup, other then to make the code more clear.&lt;BR /&gt;&lt;BR /&gt;Elmar&amp;gt; And you have a closing curly bracket wrong, resulting in missing the first lines...&lt;BR /&gt;&lt;BR /&gt;Ooops! Thanks for catching that.&lt;BR /&gt;&lt;BR /&gt;Groetjes,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 28 Aug 2004 08:37:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/delete-last-two-lines/m-p/3365707#M867378</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-08-28T08:37:27Z</dc:date>
    </item>
  </channel>
</rss>

