-2

I have a file output.txt. File looks like this:

name1 10
name2 12
name3 5

I get a number n and I need to remove all lines which have number (after name) smaller or equal to number n.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Jakub Rosina
  • 59
  • 2
  • 7
  • Did you try to make a script yourself? If so, what does that look like? In addition, csh is not a very good programming tool and has a lot of serious limitations. I would not recommend using it for new scripts. – Martin Tournoij Oct 25 '18 at 23:22
  • Do you need to use CSH for this? – kvantour Nov 13 '18 at 11:25

1 Answers1

0

Something like this:

#!/bin/csh
set CMPNUM = 5
set FILE = output.txt

set TMPFILE = ( `mktemp` )
# read in
foreach line ( "`cat $FILE`" )
  set argv = ( $line )
  set STR = $1
  set NUM = $2

  if ( `echo "$NUM > $CMPNUM" | bc` ) then
    echo "$STR $NUM" >> $TMPFILE
  endif
end
mv $TMPFILE $FILE
Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
lostbard
  • 5,065
  • 1
  • 15
  • 17