beginner: sed or awk help

beginner: sed or awk help

Post by Sharki » Fri, 26 Feb 1999 04:00:00



I need some help: how can I use either
sed or awk to look for a combination
of patterns in a text file?

For. ex I need to find all occurrences
of "To_Char" AND "YYYY" on the same line.
There might be some other irrelevant stuff
in between.

grep won't do it since it will find only
one of these patterns.

I'm using bash as a shell.

Thanks for any answers

 
 
 

beginner: sed or awk help

Post by Raj Srikantha » Fri, 26 Feb 1999 04:00:00


grep "To_Char" | grep "YYYY"    will work
- Raj

>I need some help: how can I use either
>sed or awk to look for a combination
>of patterns in a text file?

>For. ex I need to find all occurrences
>of "To_Char" AND "YYYY" on the same line.
>There might be some other irrelevant stuff
>in between.

>grep won't do it since it will find only
>one of these patterns.

>I'm using bash as a shell.

>Thanks for any answers


 
 
 

beginner: sed or awk help

Post by Al Shark » Fri, 26 Feb 1999 04:00:00



> I need to find all occurrences
> of "To_Char" AND "YYYY" on the same line.
> There might be some other irrelevant stuff
> in between.

If they always appear in that order, grep will work:

grep "To_Char.*YYYY" text_file

If YYYY can preceed To_Char, and you want both:

awk '/To_Char/ && /YYYY/' text_file

 
 
 

beginner: sed or awk help

Post by Ken Pizzi » Fri, 26 Feb 1999 04:00:00



>I need some help: how can I use either
>sed or awk to look for a combination
>of patterns in a text file?

>For. ex I need to find all occurrences
>of "To_Char" AND "YYYY" on the same line.
>There might be some other irrelevant stuff
>in between.

>grep won't do it since it will find only
>one of these patterns.

Al Sharka already posted how to do this with grep or awk.
For sed there's:
  sed -e '/To_Char/!d' -e '/YYYY/!d'
or
  sed -n '/To_Char/{/YYYY/p;}'

                --Ken Pizzini

 
 
 

beginner: sed or awk help

Post by Cal Duniga » Fri, 26 Feb 1999 04:00:00


An RE is an RE, well almost.  In all three cases the RE would be the
same, just delimited differently.
    To_Char.*YYYY

If the strings can occur in either order you need the RE set of egrep
and awk.
    (To_Char|YYYY).*(To_Char|YYYY)


> I need some help: how can I use either
> sed or awk to look for a combination
> of patterns in a text file?

> For. ex I need to find all occurrences
> of "To_Char" AND "YYYY" on the same line.
> There might be some other irrelevant stuff
> in between.

> grep won't do it since it will find only
> one of these patterns.

> I'm using bash as a shell.

> Thanks for any answers

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

      Consulting                   wrong with a world in which Ken
      Modeling                     Thompson lives in obscurity and
      Training                     Bill Gates is a famous billionaire.
//////////////////////////////////////////////////////////////////////
 
 
 

beginner: sed or awk help

Post by Sharki » Fri, 26 Feb 1999 04:00:00


Thanks for all the responses. grep works best
in my case.
Now, what if I want to find "To_Char" and "YY"
but not "YYYY"?
grep "To_Char" filename | grep "YY"
will return both "YY", "YYY", and "YYYY"

I don't want to eliminate letter "Y" entirely
only directly after "YY". So on line:
"some stuff To_Char,MM/YY some other Y stuff"
I want a hit, but NOT on:
"some stuff T0_Char,MM/YYYY and more Ys to come"

can I still use grep somehow?


> I need some help: how can I use either
> sed or awk to look for a combination
> of patterns in a text file?
> For. ex I need to find all occurrences
> of "To_Char" AND "YYYY" on the same line.
> There might be some other irrelevant stuff
> in between.
> grep won't do it since it will find only
> one of these patterns.
> I'm using bash as a shell.
> Thanks for any answers

 
 
 

beginner: sed or awk help

Post by Ken Pizzi » Sat, 27 Feb 1999 04:00:00



>Thanks for all the responses. grep works best
>in my case.
>Now, what if I want to find "To_Char" and "YY"
>but not "YYYY"?
...
>can I still use grep somehow?

Here's a "perhaps close enough" version:
  grep 'To_Char.*[^Y]YY[^Y]'

Here's a more precise version, if I understand the problem correctly:
  sed -e '/To_Char/!d' -e /YYY/d -e '/YY/!d'

                --Ken Pizzini

 
 
 

beginner: sed or awk help

Post by Al A » Tue, 02 Mar 1999 04:00:00


[ Article crossposted from comp.unix.programmer,comp.unix.misc,comp.unix.shell,alt.msdos.batch,comp.os.msdos.misc,comp.os.msdos.programmer,alt.comp.editors.batch ]
[ Author was Al Aab ]
[ Posted on Sun, 28 Feb 1999 20:17:47 GMT ]

sorry. i am usig DOS
and sed15 (off simtel, compilable for unix)

DOS > type d                        
-To_Char....YYy===                    
To_Char....YY                        
ab To_Char....YYabc                  
...YYabcab To_Chars                  
...YYY abcab To_Chars                
...YY abcab To_Chars                  
ab To_Char....YYabc                  
ab To_Char....YYab                    
ab To_Char....YYYab                  
ab To_Char....YYY                    
ab To_Char....YYab                    
abTo_Char....YY-ab                    
To_Char....abYY                      

DOS > sed "/To_Char/!d; /\<YY\>/!d" d
To_Char....YY                        
...YY abcab To_Chars                  
abTo_Char....YY-ab                    
--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, seders moderator                                      sed u soon
               it is not zat we do not see the  s o l u t i o n          
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
--
=-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
al aab, seders moderator                                      sed u soon
               it is not zat we do not see the  s o l u t i o n          
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

 
 
 

1. beginner: sed or awk help

I need some help: how can I use either
sed or awk to look for a combination
of patterns in a text file?

For. ex I need to find all occurences
of "To_Char" AND "YYYY" on the same line.
There might be some other irrelevant stuff
in between.

grep won't do it since it will find only
one of these patterns.

I'm using bash as a shell.

Thanks for any answers

2. rdump to remote Exabyte tape

3. joystick control of XFree

4. sed/awk - generating Makefiles (Re: awk processing of Makefile macros)

5. Type 4 Sun Keyboard (How to disable poweroff key)

6. Please Help - Beginner - SED

7. Stopping IP masquerade on certain ports

8. Help with awk/sed word extracting

9. sed and awk help needed

10. Help with Sed or Awk task

11. Awk, Sed Help

12. help sed or awk task