McCourt2364
McCourt2364

Reputation: 61

Pattern Searching Grep

i know there are alot of answers out there - but I am yet to find one which answers my question:

Hopefully someone can help!

I have a configuration file which is laid out like so:

define name{
            name        Stephen
            URL:        www.stephen.com
}
define name {
            name        Bob
            URL:        
}

What I need to do using grep is to search this file - and if URL is blank then return the name - in the above instance, it would return Bob.

Thanks in advance.

Upvotes: 0

Views: 38

Answers (1)

Ipor Sircer
Ipor Sircer

Reputation: 3141

grep -B1 'URL:[ ]*$'|grep -oP '[ ]*name[ ]*\K.*'

Upvotes: 1

Related Questions