Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl one-liner like grep?

Tags:

linux

grep

perl

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) | perl -e 'a'

ADDED My answer here covers that and more
https://superuser.com/questions/416419/perl-for-matching-with-regex-in-terminal

like image 787
barlop Avatar asked Jan 25 '11 13:01

barlop


People also ask

How do I search and replace in Perl?

Performing a regex search-and-replace is just as easy: $string =~ s/regex/replacement/g; I added a “g” after the last forward slash. The “g” stands for “global”, which tells Perl to replace all matches, and not just the first one.

What is in Perl regex?

Regular Expression (Regex or Regexp or RE) in Perl is a special text string for describing a search pattern within a given text. Regex in Perl is linked to the host language and is not the same as in PHP, Python, etc. Sometimes it is termed as “Perl 5 Compatible Regular Expressions“.


1 Answers

(echo a; echo b; echo c) | perl -ne 'print if /a/'
like image 136
Eugene Yarmash Avatar answered Oct 10 '22 05:10

Eugene Yarmash