check if the insert statement is using column names


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check if the insert statement is using column names
# 1  
Old 01-09-2012
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
# 2  
Old 01-09-2012
Code:
$ nawk '{if($0~/a,b,c/){print "true"}else{print "false"}}' infile
true

# 3  
Old 01-09-2012
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,
# 4  
Old 01-09-2012
Sorry .. I am afraid .. Not getting your requirement .. Post some sample input and expected output ..
# 5  
Old 01-09-2012
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.
# 6  
Old 01-09-2012
Based on the input given .. expecing this .. ??!!
Code:
$ 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
$

This User Gave Thanks to jayan_jay For This Post:
# 7  
Old 01-09-2012
Thank you :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. Shell Programming and Scripting

Insert data in first column(if blank) from previous line first column

Dear Team I need to insert field(which is need to taken from previous line's first field) in first column if its blank. I had tried using sed but not find the way. Detail input and output file as below. Kindly help for same. INPUT: SCGR SC DEV DEV1 NUMDEV DCP ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

4. Shell Programming and Scripting

awk to insert a files names

I have a couple of text files which are named as 1.txt 2.txt 1000.txt 11.txt I want to cat/merge the contents of each text file into one single file like this 1 content of 1.txt 2 content of 2.txt 1000 content of 1000.txt 11 content of 11.txt (2 Replies)
Discussion started by: Lucky Ali
2 Replies

5. Shell Programming and Scripting

Transpose field names from column headers to values in one column

Hi All, I'm looking for a script which can transpose field names from column headers to values in one column. for example, the input is: IDa;IDb;IDc;PARAM1;PARAM2;PARAM3; a;b;c;p1val;p2val;p3val; d;e;f;p4val;p5val;p6val; g;h;i;p7val;p8val;p9val; into the output like this: ... (6 Replies)
Discussion started by: popesk
6 Replies

6. Shell Programming and Scripting

How to insert numbers to a in between statement

Hi Guys, I want to create a shell script that will give me the output below. I want to insert the numbers from the input file to my url addresses below. And from the numbers below, I want to separate the last digit with a period (i.e. from 222222222222 to 22222222222.2). Appreciate any help.... (14 Replies)
Discussion started by: pinpe
14 Replies

7. Shell Programming and Scripting

rearrange the column names with comma as column delimiter

Hi, I am new to shell scripting, i have requirement can any one help me out in this regrads, in directory i have file like invoice1.txt, invoice2.txt in each file i have fixed number of columns, 62 in number but they are randomly arranged.like for first file invoice1.txt can have columns... (5 Replies)
Discussion started by: madhav62
5 Replies

8. Shell Programming and Scripting

Change names in a column based on the symbols in another column

If the 4th column has - sign then the names in 3rd column has to change to some user defined names (as shown in output). Thanx input1 1 a aaaaa + 2 b bbbbb + 3 c ccccc + 4 d ddddd + 5 e eeeee + 6 f xxxxx + 8 h hhhhh +... (8 Replies)
Discussion started by: repinementer
8 Replies

9. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

10. Shell Programming and Scripting

(sed) parsing insert statement column that crosses multiple lines

I have a file with a set of insert statements some of which have a single column value that crosses multiple lines causing the statement to fail in sql*plue. Can someone help me with a sed script to replace the new lines with chr(10)? here is an example: insert into mytable(id, field1, field2)... (3 Replies)
Discussion started by: jjordan
3 Replies
Login or Register to Ask a Question