我对SQL类型文件的文本解析有一定的特定要求,下面是详细信息。
巨大的质疑:
选择可乐,col B,。。从(从db1.table1 where条件中选择*)t1左外…
使用awk。这是不是这样的:
$ awk -v RS="" '{ # read until first empty line or end gsub(/\([^)]*\)/,"PH" ++n) # replace (..) with PHn gsub(/\r?\n/,"& ") # newlines with newline and space }1' file # output
输出:
select col A, col B, . . from PH1 t1 left outer join PH1 t2 on table1.col1 = table2.col1 left outer join PH1 t3 on table2.col1 = table3.col3