Using REGEX within SED range search


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using REGEX within SED range search
# 1  
Old 06-10-2009
Using REGEX within SED range search

test data:

Quote:
typeset lfile_selection_count=${1}
typeset lcyclename_suffix=_cycle${lfile_selection_count}
CONNECT TO ${Gdb2instance_ar} user ${Gdb2user} using XXXXXXXX;
UPDATE COMMAND OPTIONS USING p OFF;
UPDATE COMMAND OPTIONS USING s ON;
LIST COMMAND OPTIONS;
alter table ${Gmdsschema}.PLN_RV_SM activate not logged initially;
INSERT into ${Gmdsschema}.PLN_RV_SM
SELECT
a11.CLNDR_MTH_ID,
FROM
${Gmdsschema}.PLN_RV_SM a11
;
alter table ${Gmdsschema}.PLN_RV_SM activate not logged initially;
INSERT into ${Gmdsschema}.PLN_RV_SM
SELECT a11.CLNDR_MTH_ID,
a11.CMPNY_GRP_CD
FROM
${Gmdsschema}.PLN_RV_SM a11
;

Code:

Code:
 
sed -n '/^[ ]*[Ss][Ee][Ll][Ee][Cc][Tt][ ]*$*/,/;/{/;/G;p;}'

What i'm trying to do with the above regex (in bleu)
  • identify upper/lower case select only when
    • select is at the beginning of the line OR preceded by a space
    • select is followed by a space or is at the end of the line.
so that i would pick up the data in GREEN and not the text in RED

I thank you in advance for your time.
# 2  
Old 06-10-2009
If your sed allows it try alternation. Or better awk.
# 3  
Old 06-10-2009
Quote:
Originally Posted by danmauer
Code:
 
sed -n '/^[ ]*[Ss][Ee][Ll][Ee][Cc][Tt][ ]*$*/,/;/{/;/G;p;}'


$* matches zero or more dollar signs.
# 4  
Old 06-10-2009
i was trying to match either a space or end of line after the word "select" -

Ultimately what i'm trying to do is extract from a file each SQL Select statement ending with a semicolumn

Last edited by danmauer; 06-10-2009 at 04:40 PM..
# 5  
Old 06-10-2009
Quote:
Originally Posted by danmauer
i was trying to match either a space or end of line after the word "select" -

This matches select (without regard to case) with zero or more spaces before or after it, and nothing else on the line:

Code:
/^ *[Ss][Ee][Ll][Ee][Cc][Tt] *$/

# 6  
Old 06-10-2009
thanks... guess i couldn't see the forest for the trees.... a space doesn't need to be [ ]

thanks agains
# 7  
Old 06-11-2009
i'm trying come up with a slightly different usage for when the word "select" is NOT solely on a line...

for the following test data:

Quote:
typeset lfile_selection_count=${1} BAD;
typeset lfile_select ion_count=${1} BAD;
typeset select ion_count=${1} GOOD;
typeset selection_count=${1} BAD;
and i'm trying to get the "GOOD" data with the following... but it's not working... i feel a bit defeated as i thought the below would work...

Code:
sed -e '/[ ]+[Ss][Ee][Ll][Ee][Cc][Tt][ ]+/,/;/!d' -e '/;/G'

shouldn't the above mean one or more spaces before and after "select"?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed/awk to delete a regex between range of lines

Hi Guys I am looking for a solution to one problem to remove parentheses in a range of lines. Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj;... (5 Replies)
Discussion started by: kshitij
5 Replies

2. Shell Programming and Scripting

Search for string on a range of lines

Hi, I am trying to parse a file searching for specific set of string and then within those set of strings finding a keyword. The script works the way that I intended it to be but I thought it could be a lot simpler may be. Any advice will be much appreciated. The script at the moment is as... (1 Reply)
Discussion started by: newbie_01
1 Replies

3. Shell Programming and Scripting

Regex - search and replace

I have file which contains data in the following format all in a single line: BDW_PUBLN_ID DECIMAL(18:0) NOT NULL PRIMARY INDEX ARGO_ACCT_DEP_PI ( OFC_ID ,CSHBX_ID ,TRXN_SEQ_NUM ,PROCG_DT ) PARTITION BY RANGE_N(PROCG_DT BETWEEN DATE '2012-03-01' AND DATE '2014-12-31' EACH INTERVAL '1' MONTH );... (4 Replies)
Discussion started by: ysvsr1
4 Replies

4. Shell Programming and Scripting

Regex : help - How to write a range in ls

Experts, Quick question for you guys: - There are a lot of files. - How to list all files in one command from arch1_171034 to 63 , in the below examples. That means how to list with ls : arch1_171034_667780.dbf to arch1_171063_667780.dbf files. Thanks . (7 Replies)
Discussion started by: rveri
7 Replies

5. Shell Programming and Scripting

Generate Regex numeric range with specific sub-ranges

hi all, Say i have a range like 0 - 1000 and i need to split into diffrent files the lines which are within a specific fixed sub-range. I can achieve this manually but is not scalable if the range increase. E.g cat file1.txt Response time 2 ms Response time 15 ms Response time 101... (12 Replies)
Discussion started by: varu0612
12 Replies

6. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

7. Shell Programming and Scripting

How do I search with regex in one spot?

Hello im new here and i shot stright with question. Mainly i wanna ask , how do i search with regexp in one spot and show the whole thing, what im trying to ask is , for eg. i do ls -l, and i see all the info for the dirs and dats. now say i wanna get all the dats that in their name they start... (2 Replies)
Discussion started by: Goroner
2 Replies

8. Shell Programming and Scripting

Converting perl regex to sed regex

I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly: if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies

9. Shell Programming and Scripting

awk search within a range.

I have this kind of file ABC UUIIIIIIIIIIII , HJHKJKL XYZ HHJJJJJJMMM ABC BBOOIO, PPLIOJK XYZ NMJKJKK ABC MMMM ABC OPOPO XYZ LLKLKLL I need to get all data from ABC till XYZ so output should be UUIIIIIIIIIIII (6 Replies)
Discussion started by: dinjo_jo
6 Replies

10. Shell Programming and Scripting

Search files between a date range

Hi people A newbie here, thrown into the deep end. I want to select the group of files with in a range of dates and perform some operation on it. Are there inbuild date libraries i can use? I did read thru the old posts on this topic. Couldnt get much idea :(, basically want to know how I... (7 Replies)
Discussion started by: zcanji
7 Replies
Login or Register to Ask a Question