Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Question: is there always a semi-colon (on its own line) to close the group of lines after ALTER? Or is there an ALTER toward the end of the file that is not closed by a semi-colon? Another question: can you understand the above code and try to elaborate it in order to match your requirements? In other words: what are your awk skills?
Question: is there always a semi-colon (on its own line) to close the group of lines after ALTER? Or is there an ALTER toward the end of the file that is not closed by a semi-colon? Another question: can you understand the above code and try to elaborate it in order to match your requirements? In other words: what are your awk skills?
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:
/^;$/
for example you may try something like:
Code:
/^;/ # semi-colon at the beginning of the line followed by anything
/;$/ # semi-colon at the end of the line
/;/ # semi-colon in the middle of other stuff (if any)
awk code explained:
Code:
/^ALTER/ {
#
# We encounter the ALTER statement at the beginning of the line:
# set the flag _ to 1 (TRUE)
#
_ = 1
}
/^;$/ {
#
# We encounter a semi-colon alone in its own line:
# print the semicolon and set the flag _ to 0 (FALSE)
#
print
_ = 0
}
#
# Depending on the value of the _ flag the line is printed or not
#
_
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 .....
...
;
I agree with arizonagroovejet...why don't you post what you've written? Or are you wanting us to write and debug your scripts for you?
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
ADD COLUMN (C1 DATATYPE);
alter table tname1
add column
(c1 number,
c2 char)
;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.