Skip to main content
1 of 4
pLumo
  • 23.2k
  • 2
  • 43
  • 70

.* in grep is always a greedy match, meaning it matches anything until the last " in the line.

You can use [^"]* instead to match anything except ".

grep -o 'Competition="[^"]*"' 'Soccer_Data.xml' | sort --unique 

Output:

Competition="FA Cup" 

Alternatively, use perl regex that provides non-greedy modifier (.*?) with grep -P if your version of grep provides that (and it will, as you have tagged your question with the [ubuntu] tag).

grep -Po 'Competition=".*?"' 'Soccer_Data.xml' | sort --unique 

or to receive only FA CUP:

grep -Po 'Competition="\K[^"]*' 'Soccer_Data.xml' | sort --unique 

Output:

FA Cup 
pLumo
  • 23.2k
  • 2
  • 43
  • 70