0

This question already has an answer here:

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;

marked as duplicate by steeldriver, ilkkachu, Kusalananda, Thomas Nyman, phk May 15 '17 at 16:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.