I have a file as below, I want to grep for lines having .c
or .cpp
extension. I have tried using cat file|grep ".c"
grep but I am getting all types of extensions as output. Please shed some light on this. Thanks in advance.
file contents are below:
/dir/a/b/cds/main.c
/dir/a/f/cmdss/file.cpp
/dir/a/b/cds/main.h
/dir/a/f/cmdss/file.hpp
/dir/a/b/cdys/main_abc.c
/dir/a/f/cmfs/file_123.cpp
grep
supports regular expressions.
$ grep -E '\.(c|cpp)$' input
-E
means 'Interpret PATTERN as an extended regular expression'\.
means a dot .
()
is a groupc|cpp
is an alternative$
is the lineendIf 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