Using REGEX within SED range search

test data:

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
    [list]
  • 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.
    [/list]

so that i would pick up the data in GREEN and not the text in RED

I thank you in advance for your time.

If your sed allows it try alternation. Or better awk.

$* matches zero or more dollar signs.

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

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

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

thanks... guess i couldn't see the forest for the trees.... a space doesn't need to be [ ]

thanks agains

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:

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...

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

shouldn't the above mean one or more spaces before and after "select"?

it should, but not all sed implementations support the '<anything>+' syntax.
to specify one or more instances, use '<anything><anything>', e.g. '[ ][ ]'

i've tried the following....

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

but still getting the following results... one bad result. :confused:

sed -e '/[ ][ ]*[Ss][Ee][Ll][Ee][Cc][Tt][ ][ ]*.*;/!d'

You are printing a range: from a line with ' select ' to a line with ';'.

sed -e '/  *[Ss][Ee][Ll][Ee][Cc][Tt]  */!d' -e '/;/G'

Can the start and end of the range be on the same line? like my 2 data examples above?

No.

If you only want one line, why ask for more?

ahhhhh.. that's where i was getting confused....

Thanks for your patience.