Find repetitive patterns

Find repetitive patterns

Post by * Tong » Mon, 21 Nov 2005 08:13:20



Hi,

How do I find a sequence of repetitive patterns.

For e.g., I want to retrieve all the "CREATE TABLE" lines from the
following format:

CREATE TABLE tb1 (
    tb1_number            NUMBER(4)  PRIMARY KEY,
[...]
    date_last_updated     DATE );

CREATE TABLE tb2 (
[...]
    ... );

I've tried the following, but both gave me more than that. I.e., maximum
set match, but I want minimum set match.

sed -n '/^CREATE TABLE/,/^$/p'
awk '/^CREATE TABLE/,/^$/{print}'

thanks

--
Tong (remove underscore(s) to reply)
  *niX Power Tools Project: http://xpt.sourceforge.net/
  - All free contribution & collection

 
 
 

Find repetitive patterns

Post by Ed Morto » Mon, 21 Nov 2005 09:52:22



> Hi,

> How do I find a sequence of repetitive patterns.

> For e.g., I want to retrieve all the "CREATE TABLE" lines from the
> following format:

> CREATE TABLE tb1 (
>     tb1_number            NUMBER(4)  PRIMARY KEY,
> [...]
>     date_last_updated     DATE );

> CREATE TABLE tb2 (
> [...]
>     ... );

> I've tried the following, but both gave me more than that. I.e., maximum
> set match, but I want minimum set match.

> sed -n '/^CREATE TABLE/,/^$/p'
> awk '/^CREATE TABLE/,/^$/{print}'

> thanks

grep '^CREATE TABLE' file
sed -n '/^CREATE TABLE/p' file
awk '/^CREATE TABLE/' file

Regards,

        Ed.

 
 
 

Find repetitive patterns

Post by * Tong » Mon, 21 Nov 2005 10:11:56



> Hi,

> How do I find a sequence of repetitive patterns.

> For e.g., I want to retrieve [...]

sorry, should work, my end expression was wrong...

--
Tong (remove underscore(s) to reply)
  *niX Power Tools Project: http://xpt.sourceforge.net/
  - All free contribution & collection

 
 
 

1. Pattern Matching Not Working When Pattern Assign To A Variable

I'm having a problem getting pattern matching to work on Solaris when
I assign the pattern to a variable (I'll be reading them from a file
in my program).  It works fine when I compare the same pattern
directly:

#!/usr/bin/ksh

mask=$(ORA-?(0|00)600)
error=ORA-00600

print "mask=$mask"
print "error=$error"

#This doesn't work
if [[ $error = $mask ]]
then
  print "match - with variable"
else
  print "no match - with variable"
fi

#This does work
if [[ $error = ORA-?(0|00)600 ]]
then
  print "match - without variable"
else
  print "no match - without variable"
fi

The output is as follows:

mask=ORA-?(0|00)600
error=ORA-00600
no match - with variable
match - without variable

This same test works fine on AIX and DEC (both statements match).
Does anyone know how to assign a pattern to a variable in Solaris and
get them to match?

2. block-major-8

3. sed pattern replacement question with pattern duplication

4. PPP Connection to Netcom

5. ksh pattern matching when pattern is in a variable

6. Remote DAT tape setup on Mandrake 8

7. grepping for pattern, and then deleting ALL the following lines after the pattern

8. Linux Drivers for Sony Ericsson GC82 Wireless Edge card

9. grep pattern within pattern

10. Substitute this pattern for that pattern EXCEPT if this is true with sed???

11. Matching Line After Pattern (Pattern Occurs Multiple Times)

12. Pattern matching and extracting the data which matches the pattern

13. finding files with multiple name patterns ?