shell script for below logic
Hi Team,
I need shell script for below logic. I have file string1 string2 string3 ALTER TABLE TNAME ADD COLUMN (C1 DATATYPE); String4 alter table tname1 add column (c1 number, c2 char) ; string 5 Now i need to extract ALTER statememnts...read from ALTER statement and end till ; is encountered. ALTER statements are not fixed in length. I need shell script to read the above file and extract alter commands till ; please help |
Code:
awk '/^ALTER/,/^;$/' file |
This smells a lot like homework. How about you post what you have so far, and then maybe someone can tell you where you're going wrong.
|
Quote:
ALTER TABLE ADD COLUMN (COL1) ; STRING3 ALTER TABLE.... STRING 4 I am getting in between strings also. Only it has removed the strings above first ALTER. I want only ALTER commands no strings in between |
Code:
awk '/^ALTER/{_=1}/^;$/{print;_=0}_' |
Quote:
ALTER statement is always ended by ; ...I need to extract only ALTER statement. I am not confortable with awk commands. The output did not change... I am getting ALTER TABLE...... .... ; string 3; ALTER TABLE ..... ... ; |
Ok. Maybe it depends on how the ending semi-colon is placed. My code looks for a semi-colon without any other character on the same line, that is no spaces before and after. Try to change the regular expression to something more suitable to your input:
Code:
/^;$/ Code:
/^;/ # semi-colon at the beginning of the line followed by anything Code:
/^ALTER/ { |
colucix: It's obvious from the original post that the semicolon is not on the same line. This should work:
Code:
awk 'BEGIN { RS="" } { gsub(/ALTER[^;]*;/, "", $0); print }' |
Quote:
|
Might also be nice if you posted the expected output seeing as the guessing game to get what you want is not working.
|
Seems to me those are (prob Oracle) SQL Alter Table ...; statements, with other strings in between (possibly comments).
He just wants the SQL out, presumably to run directly. Therefore, give the example in post #1, output would be Code:
ALTER TABLE TNAME |
Hi,
I will work with your inputs. Thanks for your time and information |
All times are GMT -5. The time now is 05:50 PM. |