<?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: ksh script Q about removing entries from a list in a VAR in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137594#M93230</link>
    <description>When I tried the answer I see I got the opposite of what I was looking for.  It got the two files I want to take off the list.  But since they are identified, I have a way to mask them out.  Here is my code.  &lt;BR /&gt;&lt;BR /&gt;LAST2LIST=`ls -1tr log.?????? | tail -2`&lt;BR /&gt;LIST=`ls -1tr log.??????`&lt;BR /&gt;echo "orig"&lt;BR /&gt;echo "$LIST"&lt;BR /&gt;NLIST=&lt;BR /&gt;for Y in $LIST&lt;BR /&gt;  do&lt;BR /&gt;  Flag=0&lt;BR /&gt;  for X in $LAST2LIST&lt;BR /&gt;    do&lt;BR /&gt;    if [  "$X" = "$Y" ] ; then&lt;BR /&gt;      Flag=1&lt;BR /&gt;    fi&lt;BR /&gt;  done&lt;BR /&gt;  if [ $Flag -eq 0 ] ; then&lt;BR /&gt;     NLIST="$NLIST $Y"&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;LIST="$NLIST"&lt;BR /&gt;echo "after"&lt;BR /&gt;for Y in $LIST&lt;BR /&gt;   do&lt;BR /&gt;   echo $Y&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Perhaps there is a more elegant way to perform this?&lt;BR /&gt;</description>
    <pubDate>Wed, 30 Jan 2008 14:37:32 GMT</pubDate>
    <dc:creator>Steve Post</dc:creator>
    <dc:date>2008-01-30T14:37:32Z</dc:date>
    <item>
      <title>ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137591#M93227</link>
      <description>I can think of how do this in perl, but I know it should be easily done in ksh.&lt;BR /&gt;&lt;BR /&gt;I have a list of files in a variable.&lt;BR /&gt;MYLIST=`ls -1tr logs.*`&lt;BR /&gt;(That's one-t-r, not EL-t-r). &lt;BR /&gt;Because I ordered the files by time, the last two files on the list are the latest 2 files.&lt;BR /&gt;&lt;BR /&gt;I want to remove the latest two logs from the list. &lt;BR /&gt;&lt;BR /&gt;I can't wrap my brain around how to do this.  Then I realized this is a good question for the forums.  It would be good to see different methods to handle it. &lt;BR /&gt;&lt;BR /&gt;In perl it would be: &lt;BR /&gt;( @goodlist, $last2, $last1) = ( @filelist );&lt;BR /&gt;But this isn't perl.  &lt;BR /&gt;&lt;BR /&gt;The script would be like this:&lt;BR /&gt;MYLIST=`ls -1tr logs.*`&lt;BR /&gt;# unknown magic code to remove latest 2 files goes here&lt;BR /&gt;for F in $MYLIST&lt;BR /&gt;    do&lt;BR /&gt;    rm $F&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;any help would be appreciated.&lt;BR /&gt;&lt;BR /&gt;steve&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jan 2008 13:55:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137591#M93227</guid>
      <dc:creator>Steve Post</dc:creator>
      <dc:date>2008-01-30T13:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137592#M93228</link>
      <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;# MYLIST=$(ls -1tr /tmp|tail -2|xargs)&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 30 Jan 2008 14:00:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137592#M93228</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-01-30T14:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137593#M93229</link>
      <description>Hi (again) Steve:&lt;BR /&gt;&lt;BR /&gt;Actually, since you just want to compose the list in the variable, you don't need the 'xargs'.  &lt;BR /&gt;&lt;BR /&gt;# MYLIST=$(ls -1tr /tmp|tail -2)&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 30 Jan 2008 14:02:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137593#M93229</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-01-30T14:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137594#M93230</link>
      <description>When I tried the answer I see I got the opposite of what I was looking for.  It got the two files I want to take off the list.  But since they are identified, I have a way to mask them out.  Here is my code.  &lt;BR /&gt;&lt;BR /&gt;LAST2LIST=`ls -1tr log.?????? | tail -2`&lt;BR /&gt;LIST=`ls -1tr log.??????`&lt;BR /&gt;echo "orig"&lt;BR /&gt;echo "$LIST"&lt;BR /&gt;NLIST=&lt;BR /&gt;for Y in $LIST&lt;BR /&gt;  do&lt;BR /&gt;  Flag=0&lt;BR /&gt;  for X in $LAST2LIST&lt;BR /&gt;    do&lt;BR /&gt;    if [  "$X" = "$Y" ] ; then&lt;BR /&gt;      Flag=1&lt;BR /&gt;    fi&lt;BR /&gt;  done&lt;BR /&gt;  if [ $Flag -eq 0 ] ; then&lt;BR /&gt;     NLIST="$NLIST $Y"&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;LIST="$NLIST"&lt;BR /&gt;echo "after"&lt;BR /&gt;for Y in $LIST&lt;BR /&gt;   do&lt;BR /&gt;   echo $Y&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Perhaps there is a more elegant way to perform this?&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jan 2008 14:37:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137594#M93230</guid>
      <dc:creator>Steve Post</dc:creator>
      <dc:date>2008-01-30T14:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137595#M93231</link>
      <description>Bonjour Steve,&lt;BR /&gt;&lt;BR /&gt;Do you really need the list in a reverse order ? I mean do you use -r option only as a way to isolate the 2 latest files ?&lt;BR /&gt;&lt;BR /&gt;If so, don't use -r option and have the latest files first. So it becomes simplier to remove them :&lt;BR /&gt;&lt;BR /&gt;MYLIST=`ls -1t logs.* | tail -n +2`&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Eric</description>
      <pubDate>Wed, 30 Jan 2008 15:04:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137595#M93231</guid>
      <dc:creator>Eric SAUBIGNAC</dc:creator>
      <dc:date>2008-01-30T15:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137596#M93232</link>
      <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;I'm sorry, I didn't read your requirement very well!  &lt;BR /&gt;&lt;BR /&gt;NO POINTS PLEASE!&lt;BR /&gt;&lt;BR /&gt;Anyway, one way in a shell would be to pipe the 'ls' output to a temporary file.  Now, knowing the number of records in the file, loop, reading all but the last two.&lt;BR /&gt;&lt;BR /&gt;By the way, in Perl your example would be:&lt;BR /&gt;&lt;BR /&gt;# perl -le '@list=qw(a b c d e f);($x,$y,@good)=(@list);print "@good"'&lt;BR /&gt;&lt;BR /&gt;In your post, '@goodlist' would greedily suck up all of '@filelist'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 30 Jan 2008 15:07:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137596#M93232</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-01-30T15:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137597#M93233</link>
      <description>Sorry, did a mistake ;-(&lt;BR /&gt;&lt;BR /&gt;It was :&lt;BR /&gt;&lt;BR /&gt;MYLIST=`ls -1t logs.* | tail -n +3`&lt;BR /&gt;&lt;BR /&gt;Eric&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jan 2008 15:13:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137597#M93233</guid>
      <dc:creator>Eric SAUBIGNAC</dc:creator>
      <dc:date>2008-01-30T15:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137598#M93234</link>
      <description>Yep.  I didn't really try the perl.  If I did, I would have caught that.  &lt;BR /&gt;&lt;BR /&gt;Now the "tail -n -2" only grabs the last 2 lines.  These are the two lines I don't want.  I kept trying this and could not get it to work. &lt;BR /&gt;&lt;BR /&gt;BUT.....I found an elegant way after all.  &lt;BR /&gt;&lt;BR /&gt;ls -1tr logs.* | sed '$d' | sed '$d'&lt;BR /&gt;This gives me the list of logs from earliest to latest.  Then sed '$d' removes the bottom line.  The second sed '$d' removes the bottom line again (ie the 2nd to last file).&lt;BR /&gt;&lt;BR /&gt;Now perhaps there is something stupid about this I don't see.  Maybe there is a sed command to remove the bottom two lines in one command instead of piping it twice?&lt;BR /&gt;&lt;BR /&gt;steve</description>
      <pubDate>Wed, 30 Jan 2008 15:36:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137598#M93234</guid>
      <dc:creator>Steve Post</dc:creator>
      <dc:date>2008-01-30T15:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137599#M93235</link>
      <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;Eric has the simple solution.  See _his_ _second _post_.  It's the difference between +n and -n in 'tail' that I always forget!&lt;BR /&gt;&lt;BR /&gt;NO POINTS PLEASE&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 30 Jan 2008 15:47:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137599#M93235</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-01-30T15:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137600#M93236</link>
      <description># ls -1tr | awk '{x[NR]=$0} END {for(i=1;i&lt;NR-1&gt;&lt;/NR-1&gt;</description>
      <pubDate>Wed, 30 Jan 2008 15:49:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137600#M93236</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2008-01-30T15:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137601#M93237</link>
      <description>I find Sandman! post really attractive as it gives the answer with the reverse order that Steve wanted ;-)&lt;BR /&gt;&lt;BR /&gt;Of course NO POINT&lt;BR /&gt;&lt;BR /&gt;Eric&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jan 2008 15:57:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137601#M93237</guid>
      <dc:creator>Eric SAUBIGNAC</dc:creator>
      <dc:date>2008-01-30T15:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137602#M93238</link>
      <description>Ok let me summarize.....&lt;BR /&gt;one way:   ls -1tr | sed '$d' | sed '$d'&lt;BR /&gt;I don't like that I pipe to sed twice.&lt;BR /&gt;&lt;BR /&gt;one way:  ls -1t | tail -n +3&lt;BR /&gt;The +3 means to tail line 3 and up. (tail -n -3 would be the last 3 lines).&lt;BR /&gt;If the number of lines in the ls command is a very large number, the tail would fail.  But this will be a small number of files.&lt;BR /&gt;&lt;BR /&gt;one way: ls -1tr | awk '{x[NR]=$0} END {for(i=1;i&lt;NR-1&gt;&lt;/NR-1&gt;This awk script is nice.  But I wouldn't use it until I knew people looking at it would understand it.  And I would hope it worked on all versions of awk.&lt;BR /&gt;&lt;BR /&gt;For me, I like the tail idea the best.  But I REALLY like the fact that there is more than one way to do it. &lt;BR /&gt;&lt;BR /&gt;Thank you all.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Jan 2008 16:59:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137602#M93238</guid>
      <dc:creator>Steve Post</dc:creator>
      <dc:date>2008-01-30T16:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137603#M93239</link>
      <description>You said "But I wouldn't use it until I knew people looking at it would understand it. ". So I make the post for Sandman! as he can't control himself !&lt;BR /&gt;&lt;BR /&gt;{x[NR]=$0}&lt;BR /&gt;&lt;BR /&gt;==&amp;gt; For each line initialize an array (x) with the line itself ($0). NR is the current line number&lt;BR /&gt;&lt;BR /&gt;END {for(i=1;i&lt;NR-1&gt;&lt;/NR-1&gt;&lt;BR /&gt;==&amp;gt; at end of input stream, that is ls -1tr, just print all lines but the two last&lt;BR /&gt;&lt;BR /&gt;It will work ... assuming that number of files listed is not greater that the limit of awk on array sizes.&lt;BR /&gt;&lt;BR /&gt;No needs to give POINT&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Eric</description>
      <pubDate>Wed, 30 Jan 2008 17:11:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137603#M93239</guid>
      <dc:creator>Eric SAUBIGNAC</dc:creator>
      <dc:date>2008-01-30T17:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: ksh script Q about removing entries from a list in a VAR</title>
      <link>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137604#M93240</link>
      <description>hi Steve:&lt;BR /&gt;&lt;BR /&gt;So, if 'tail', sed' and 'awk' are OK for the filters, why not Perl?&lt;BR /&gt;&lt;BR /&gt;# ls -1tr|perl -nle 'push @a,$_;END{print "@a[2..$#a]"}'&lt;BR /&gt;&lt;BR /&gt;After all, TMTOWTDI.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF..</description>
      <pubDate>Wed, 30 Jan 2008 17:20:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/ksh-script-q-about-removing-entries-from-a-list-in-a-var/m-p/4137604#M93240</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-01-30T17:20:51Z</dc:date>
    </item>
  </channel>
</rss>

