tags:

views:

64

answers:

2

I have a file containing a list of file names:

esocket.c
esocket.h
dockwin.cpp
dockwin.h
makefile
getblob
.
etc...

I am looking for a regular expression (preferably unix syntax) to do the following:

  1. get lines that have .c, cpp and .h files
  2. get lines that don't have a file extension.
+2  A: 
 egrep '^[^.]*(\.(cpp|c|h))?$' yourfile
Pointy
+1  A: 

gawk

awk '
{
 for(i=1;i<=NF;i++){
   if ( $i ~ /\.(c|h|cpp)$/){
    print "file with extension: "$i
   }else{
    print "file w/o extension: "$i
   }
 }
}' file

output

$ ./shell.sh
file with extension: esocket.c
file with extension: esocket.h
file with extension: dockwin.cpp
file with extension: dockwin.h
file w/o extension: makefile
file w/o extension: getblob
ghostdog74