这是我昨天遇到的另一个问题Awk doesn't match all match all my entries的下一部分。 我想用perl替换awk,我的第一个目标是在.c中提取我的函数声明并将其放在.h中。所以我想出了这个:
cat dict3.c | perl -ne '/([a-z_*]+[[:space:]]+[a-z_*]+[[:space:]]*\(.*?\))/i; print $1 . ";\n"'
但输出结果是:
;
;
;
;
;
;
;
;
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dictent_t* dictentcreate(const char * key, const char * val);
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
dict_t* dictcreate();
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdestroy(*dict_t d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
void dictdump(dict_t *d);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictlook(dict_t *d, const char * key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
int dictget(char* s, dict_t *d, const char *key);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t* dictadd(dict_t* d, const char * key, const char * val);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t dictup(dict_t d, const char * key, const char * newval);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
dict_t* dictrm(dict_t* d, const char * key);
而文件中的每个函数只有一个声明。 我不知道它可能是什么,因为每条印刷线的重复次数不一样,所以它不能只是一个循环......
答案 0 :(得分:4)
因为您在匹配正则表达式时没有使print
命令条件。试试这个:
perl -ne '/([\w*]+\s+[\w*]+\s*\(.*?\))/i and print $1 . ";\n"' dict3.c
# .......................................^^^
对于每一行,您都是从上次成功匹配打印匹配的文本。