perl one-liner like grep?

后端 未结 3 2032
一整个雨季
一整个雨季 2021-02-13 03:17

i\'d like perl to do a one-liner like grep

a bit like this, but i\'m not sure what to add to make it work

$ (echo a ; echo b ; echo c) | per         


        
相关标签:
3条回答
  • 2021-02-13 03:39

    To echo mob's comment:

    If you want to use Perl regexes try ack: http://betterthangrep.com/

    0 讨论(0)
  • 2021-02-13 03:41
    (echo a; echo b; echo c) | perl -ne 'print if /a/'
    
    0 讨论(0)
  • 2021-02-13 03:43

    You can do the same with Ruby, if you can afford other options

    $ (echo a; echo b; echo c) | ruby -ne 'print if /a/'
    a
    $ (echo a; echo b; echo c) | ruby -ne 'print if $_["a"]'
    a
    
    0 讨论(0)
提交回复
热议问题