我有以下变量:
grep_line_new_file='create table "informix".issue'
new_file_below=`awk 'BEGIN { FS="\n[()]"; RS=";" } /$grep_line_new_file/ { print ")"$NF";"}' test`
内部测试文件我有以下内容:
create table "informix".issue
(
issue_no serial not null constraint "informix".nnc_issue00,
user_logged varchar(8,1) not null constraint "informix".nnc_issue01,
issue_status_code integer not null constraint "informix".nnc_issue02,
issue_cat_code varchar(2) not null constraint "informix".nnc_issue03,
issue_descr text not null constraint "informix".nnc_issue04,
issue_feedback text,
user_action varchar(8,1),
date_logged date not null constraint "informix".nnc_issue05,
date_compl date
) in datadbs extent size 16 next size 16 lock mode row;
revoke all on "informix".issue from "public" as "informix";
当回显“$new_file_below”时,我在使用外部变量查找并获取下面的行时遇到问题。
我尝试过使用下面的[awk -v]。它仍然不想工作:
new_file_below=`awk -v val="$grep_line_new_file" 'BEGIN { FS="\n[()]"; RS=";" } /$val/ { print ")"$NF";"}' test`
我需要“new_file_below”变量的结果如下:
) in datadbs extent size 16 next size 16 lock mode row;
答案1
我弄清楚了如何在 awk 中的变量内以模式传递变量:
grep_line_new_file='create table "informix".issue'
new_file_below=`awk 'BEGIN { FS="\n[()]"; RS=";" } /'"$grep_line_new_file"'/ { print ")"$NF";"}' test`
输出:
create table "informix".issue
) in datadbs extent size 16 next size 16 lock mode row;