LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 11-13-2014, 10:52 AM   #1
mierdatuti
Member
 
Registered: Aug 2008
Posts: 54

Rep: Reputation: 15
extract text between two strings


Hi,

I have some a script where I must extract all sql sentences.
To do these I see that I must extract from the literal ${SCR}/LIST_{Q}.SH "
I have:
Code:
VAR=${1}
1PART=`${SCR}/LIST_{Q}.SH "SELECT '(RETN_'||TO_NUMBER ( TO_CHAR ( SYSDATE-1, 'YYYYMM' ))||')' FROM DUAL;"`
V_PARTICION2=`${SCR}/LIST_{Q}.SH "SELECT '(RETN_ '||TO_NUMBER ( TO_CHAR ( SYSDATE-1, 'YYYYMM' ))||')' FROM DUAL;"`
${SCR}/LIST_{Q}.SH "
SET SERVEROUTPUT ON SIZE 10000
EXEC PACKAGE.REALITY ('LIST_BOJECTSO')
CREATE TABLE CANION AS
SELECT CAMPAIGN, ROWNUM 
FROM TERR
WHERE TABLE_NAME='SALE';
DECLARE
I NUMBER;
J NUMBER;
LIST VARCHAR2(64 BYTE);
VAR VARCHAR2(4000 BYTE);
BEGIN
I:=1;
SELECT MAX(ROW) INTO J  FROM VAR;
CADENA:=CHR(39);
LOOP
I:=I+1;
EXIT WHEN I>J;
COMMIT;
END;
/
"
And I would like to extract:
Code:
SELECT '(RETN'||TO_NUMBER ( TO_CHAR ( SYSDATE-1, 'YYYYMM' ))||')' FROM DUAL;
SELECT '(RETN_'||TO_NUMBER ( TO_CHAR ( SYSDATE-1, 'YYYYMM' ))||')' FROM DUAL;
SET SERVEROUTPUT ON SIZE 10000
EXEC PACKAGE.REALITY ('LIST_BOJECTSO')
CREATE TABLE CANION AS
SELECT CAMPAIGN, ROWNUM 
FROM TERR
WHERE TABLE_NAME='SALE';
DECLARE
I NUMBER;
J NUMBER;
LIST VARCHAR2(64 BYTE);
VAR VARCHAR2(4000 BYTE);
BEGIN
I:=1;
SELECT MAX(ROW) INTO J  FROM VAR;
CADENA:=CHR(39);
LOOP
I:=I+1;
EXIT WHEN I>J;
COMMIT;
END;
/
Could you help me please.
Thanks
 
Old 11-13-2014, 01:21 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,853

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
sql.awk

Code:
{
	if (keep == 0) {fnd=index($0,"${SCR}/LIST_{Q}.SH"); 
		if (fnd) {i=index($0,"\""); 
			$0 = substr($0,i+1); 
			keep=1}
	}
	if (keep) {i=index($0,"\""); 
		if (i) {print substr($0,1,i-1); keep=0} 
		else print $0;
	}
}
awk -f sql.awk < your_input
 
Old 11-20-2014, 03:18 AM   #3
mierdatuti
Member
 
Registered: Aug 2008
Posts: 54

Original Poster
Rep: Reputation: 15
problem with awk

Hi,
I have these text file:
Code:
SET SERVEROUTPUT ON SIZE 100
EXCE PACKAGE.REM_OB('COLECT_PEM');
EXCE PACKAGE.REM_LG ('TABLE CREATED COLECT_PEM', 'COLECT_FRON.SH');
CREATE TABLE COLECT_PEM AS
SELECT CAR, ROWNUM FILA
FROM CAMP_REMPOM
WHERE TABLA='FRONT_RET';
EXCE PACKAGE.REM_OB('COLECT_PEM2');
EXCE PACKAGE.REM_LG ('TABLE CREATED COLECT_PEM2', 'COLECT_FRON.SH');
CREATE TABLE COLECT_PEM2 (TOTAL_CAMP VARCHAR2(4000 BYTE));
DECLARE
I NUMBER;
J NUMBER;
CAR VARCHAR2(64 BYTE);
CHAIN VARCHAR2(4000 BYTE);
BEGIN
I:=1;
SELECT MAX(FILA) INTO J  FROM COLECT_PEM;
CHAIN:=CHR(39);
LOOP
SELECT CAR INTO CAR FROM COLECT_PEM WHERE FILA=I;
CHAIN:=CHAIN||CAR||CHR(39)||','||CHR(39);
I:=I+1;
EXIT WHEN I>J;
COMMIT;
END LOOP;
INSERT INTO COLECT_PEM2 SELECT '('||SUBSTR(CHAIN,1, LENGTH(CHAIN)-2)||')' FROM DUAL;
COMMIT;
END;
/

SELECT TOTAL_CAMP FROM COLECT_PEM2;
SELECT COUNT(*) FROM ALL_TABLES WHERE TABLE_NAME='TEMP_CHKCKS' AND OWNER='LOGISTIC';
I'm trying to extract all select sentences with awk. I do :
Code:
{
        if (keep == 0) {index($0,"SELECT");
                        keep=1;
        }
        if (keep) {i=index($0,";");
                if (i) {print substr($0,1,i-1); keep=0}
                else print $0;
        }
}
But doesn't works.
Any help with awk? Many thanks
 
Old 11-20-2014, 03:31 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,995

Rep: Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218Reputation: 2218
So you take an answer to your previous thread (without attribution), and start another thread without any apparent effort yourself ?.
Bad form.
 
Old 11-20-2014, 03:47 AM   #5
mierdatuti
Member
 
Registered: Aug 2008
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by syg00 View Post
So you take an answer to your previous thread (without attribution), and start another thread without any apparent effort yourself ?.
Bad form.
Sorry, I'm trying to understand the other thread and I think that I understand the awk sentences. So I modified to can extract other things of my text and I think is right but it seems that I'm doing something wrong.

EDIT
=====
I solved it:

Code:
{
        if (keep == 0) {fnd=index($0,"SELECT");
                     if (fnd) keep=1;
        }
        if (keep) {i=index($0,";");
                if (i) {print substr($0,1,i-1); keep=0}
                else print $0;
        }
}

Last edited by mierdatuti; 11-20-2014 at 04:18 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
turning awk command line entries into awk scripts tabbyagirl Linux - Newbie 5 08-22-2013 01:46 AM
[SOLVED]Wierd AWK behavior / AWK not reading first line. Involar Linux - Newbie 9 11-28-2012 11:53 AM
awk error awk: line 2: missing } near end of file boscop Linux - Networking 2 04-08-2012 11:49 AM
[SOLVED] call awk from bash script behaves differently to awk from CLI = missing newlines titanium_geek Programming 4 05-26-2011 10:06 PM
[awk] NR problem dhodho Programming 4 08-13-2010 05:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration