0

I have the below variables:

grep_line_new_file='create table "informix".issue'
new_file_below=`awk 'BEGIN { FS="\n[()]"; RS=";" } /$grep_line_new_file/ { print ")"$NF";"}' test`

Inside test file I have the below:

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";

I am having an issue using an external variable to find and get the line below I need when echoing the "$new_file_below".

I have tried using the below [awk -v]. It still does not want to work:

new_file_below=`awk -v val="$grep_line_new_file" 'BEGIN { FS="\n[()]"; RS=";" } /$val/ { print ")"$NF";"}' test`

The outcome I need from the "new_file_below" variable is below:

) in datadbs extent size 16 next size 16 lock mode row;
ilkkachu
  • 138,973
  • 2
    Again, you had the question tagged with both [linux] and [hp-ux] while the question itself seems to be more about awk (and possibly shell), instead of being specific to either of the OS's. Let alone both at the same time. – ilkkachu May 15 '17 at 12:52

1 Answers1

0

I figured out how to pass a variable in a pattern within a variable within an awk:

grep_line_new_file='create table "informix".issue'
new_file_below=`awk 'BEGIN { FS="\n[()]"; RS=";" } /'"$grep_line_new_file"'/ { print ")"$NF";"}' test`

output:

create table "informix".issue
) in datadbs extent size 16 next size 16 lock mode row;