我有一个包含文件名列表的文件:
esocket.c
esocket.h
dockwin.cpp
dockwin.h
makefile文件
getblob
。
等...
我正在寻找一个正则表达式(最好是Unix语法)来执行以下操作:
答案 0 :(得分:2)
egrep '^[^.]*(\.(cpp|c|h))?$' yourfile
答案 1 :(得分:1)
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
输出
$ ./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