Reputation: 199
I have the following exmaple of a text file:
AFUA_2G08360|pyrG
AFUA_2G12630
gel1|bgt2|AFUA_2G01170
and I wish to do a regex to filter out AFUA_2G08360
, AFUA_2G12630
, AFUA_2G01170
using perl -l -ne
in unix command line.
How would you suggest to do that?
Upvotes: 1
Views: 137
Reputation: 67211
use
perl -pe 's/.*(AFUA_[0-9a-zA-Z]*).*$/\1/' your_file
tested:
> cat temp
AFUA_2G08360|pyrG
AFUA_2G12630
gel1|bgt2|AFUA_2G01170
> perl -pe 's/.*(AFUA_[0-9a-zA-Z]*).*$/\1/' temp
AFUA_2G08360
AFUA_2G12630
AFUA_2G01170
Upvotes: 0
Reputation: 43235
AFUA_[0-9A-Za-z]{7}
See here : http://regexr.com?328gj
Command line :
user@mch:/tmp$ cat input.txt
AFUA_2G08360|pyrG
AFUA_2G12630
gel1|bgt2|AFUA_2G01170
user@mch:/tmp$ cat input.txt | perl -lne "@matches = /AFUA_[0-9A-Za-z]{7}/g; print join("\n", @matches)";
AFUA_2G08360
AFUA_2G12630
AFUA_2G01170
Upvotes: 0
Reputation: 13356
Here is a doable one-liner for your example input.
cat data | perl -l -e 'while (<>) {s/.*(AFUA_[^\|]*).*/\1/g; print}'
Upvotes: 0