troubleshooting Question

help with grep in script

Avatar of lolaferrari
lolaferrariFlag for United Kingdom of Great Britain and Northern Ireland asked on
Unix OS
4 Comments1 Solution328 ViewsLast Modified:
I have a text file below where I only want to extract the line NAME and then the first two occurences of "file was .." afterwards but i can't get beyond what i've tried here - any ideas?

cat test | egrep  '(^NAME |file)'

 textfile

NAME test
FILE: 2.0
SUBVERSION 1.0
HEADER: 1.3

        file was ( here )
        file was ( there )
        file was ( everywhere )
        file was ( everywhere )
        file was ( everywhere )
        file was ( here )
        file was ( there )
        file was ( everywhere )
        file was ( everywhere )
        file was ( everywhere )

junk is
here to stay
and on
and on

NAME test2
FILE 1.0
SUBVERSION 1.0
HEADER: 1.4

        file was ( here )
        file was ( there )
        file was ( everywhere )
        file was ( everywhere )
        file was ( everywhere )

junk is
here to stay
and on
and on

NAME test67
FILE 3.0
SUBVERSION 1.0
HEADER: 1.4

        file was ( here )
        file was ( there )
        file was ( everywhere )
        file was ( everywhere )
        file was ( everywhere )
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros