check if the insert statement is using column names

Hi,

Input- a file comtaining a procedure or function with various statements in that one of the statement would be
insert into table1 (a,b,c) values (1,2,3)

ourput required
true if insert statement is using column name (a,b,c) else false.

Please suggest

$ nawk '{if($0~/a,b,c/){print "true"}else{print "false"}}' infile
true

Hi jay,
Thanks for your quick reply..

here a,b,c can be any thing.. like proper name of the columns and there can be multiple insert statements..
for all the insert statements the command should search if insert statement is inserting using column names.

Thanks,

Sorry .. I am afraid .. Not getting your requirement .. Post some sample input and expected output ..

Input:-

insert into table_Name (column1,column2,column3) values(1,2,3)

output
since the above insert statement is using columns names for inserting into a table print true.

input:-
insert into table_Name values(1,2,3)
output:-
since the above insert statement is not using columns names for inserting into table print false.

Based on the input given .. expecing this .. ??!!

$ cat infile
insert into table_Name (column1,column2,column3) values(1,2,3)
insert into table_Name values(1,2,3)
$
$ nawk '{if($0~/insert into table_Name \(/){print $0" --> true"}else{print $0" --> false"}}' infile
insert into table_Name (column1,column2,column3) values(1,2,3) --> true
insert into table_Name values(1,2,3) --> false
$
1 Like

Thank you :slight_smile:

If table_name is not consistent .. :wink:

$ nawk '/insert/ {if($4!~/values/){print $0" --> true"}else{print $0" --> false"}}' infile
insert into table_Name (column1,column2,column3) values(1,2,3) --> true
insert into table_Name values(1,2,3) --> false

the above code is not working.
but i see it is as expected in you out put can you pleas ehelp me?

below is the output from my file
insert into table_name values(1,2,3) --> false
insert into table_name (c1,c2,c3) values (1,2,3) --> false

for the first statement it should be false for the second statement it should be true.

---------- Post updated at 12:34 PM ---------- Previous update was at 12:30 PM ----------

It is working file. sorry for the confusion