On Mon, Nov 21, 2016 at 6:34 PM, Die Optimisten
<inform / die-optimisten.net> wrote:
>> That is not a reply to my question though. I wondered why you asked your
>> question in the first place (see at thread start). What do you need that
>> for?

> I wanted a simple grep for textlines, without converting to an array (array
> makes no sense, epecially, for a long text)

This typically involves Ruby's command line options -e and -n or -p. A few ways

$ seq 6 11 | ruby -ne 'if /../; puts $_ end'
10
11
$ seq 6 11 | ruby -pe 'unless /../;$_=nil end'
10
11

> Similar for sort: as far as I read, there is no uniq (sort -u) (for
> following lines only).

$ { seq 6 11; seq 2 8; } | ruby -e 'puts ARGF.sort_by(&:to_i).uniq'
2
3
4
5
6
7
8
9
10
11

If there are many duplicates then this is probably more efficient:

$ { seq 6 11; seq 2 8; } | ruby -r set -e 'puts ARGF.to_set.sort_by(&:to_i)'
2
3
4
5
6
7
8
9
10
11


Cheers

robert

-- 
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>