I've got a file with numbers from -100 to 100, I only want to print from -10 to 10
Currently, I'm at
egrep '[0-9][0-3]'
Which, unfortunately, prints -13, -12, -11, -10, 10, 11, 12, 13, 20, 21, 22, 23.
I've got a file with numbers from -100 to 100, I only want to print from -10 to 10
Currently, I'm at
egrep '[0-9][0-3]'
Which, unfortunately, prints -13, -12, -11, -10, 10, 11, 12, 13, 20, 21, 22, 23.
this is basically two regexs one to get 10,-10 and one to get all the singular numbers
Have a try with that regular expression:
So the call on CLI would be:
Why?
This is not about egrep, since from your comments it seems you don't want egrep for its own sake here are some alternatives:
use seq:
seq first inc last
seq -15 1 14
will print all numbers between -15 to 14 each on his own lineuse awk:
awk '{ if ($1 >= first && $1 <= last) print $1 }' filename
awk '{ if ($1 >= -15 && $1 <= 14) print $1 }' numbers.txt
will print all numbers between -15 to 14 each on his own lineuse perl:
perl -lane 'print $_ if $_ >= first && $_ <= last' filename
perl -lane 'print $_ if $_ >= -15 && $_ <= 14' numbers.txt
will print all lines between -15 to 14 each on his own linehope it helps