I am trying to read/grep a particular word or content that is before a period (.
).
e.g. file1
has abinaya.ashok
and I want to grep whatever is before the period (.
) without hardcoding anything.
if I try
grep \.\ file1
it gives abinaya.ashok
.
I've tried: grep\*\.\ file1
it doesn't give anything.Can we find it using grep commands or should we do it only using awk command? Any thoughts?
Using GNU grep
for PCRE
regex (for non-greedy and positive look-ahead), you can do:
echo 'abinaya.ashok' | grep -oP '.*?(?=\.)'
abinaya
Using awk
:
echo 'abinaya.ashok' | awk -F\. '{print $1}'
abinaya
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With