Prash N
Prash N

Reputation: 3

Extracting data between single quotes using sed or awk or grep when there are multiple single quoted data

I have a sample text like this

-message {This is a block with single quotes 'single_quoted_data'(domain 'this_is_the_first_domain(dov vcc:0.897 and vmm)') the next quoted data 'second_single_quoted_data'(domain 'this_is_the_second_domain(dov vcc:0.897 and vmm)') then some more text}

here I want to extract:

single_quoted_data and second_single_quoted_data.

Please suggest an optimum way. I tried with grep -o followed by sed but it didnt work

Upvotes: 0

Views: 161

Answers (2)

RavinderSingh13
RavinderSingh13

Reputation: 133680

@Prash:try:

awk -F"'" '{for(i=1;i<=NF;i++){if($i ~ /quoted_data/){print $i}}}'   Input_file

Upvotes: 0

Michael Vehrs
Michael Vehrs

Reputation: 3363

You just need a suitable regexp:

grep -Eo "'[^'() ]+'" 

Upvotes: 1

Related Questions