G murali Madhav
G murali Madhav

Reputation: 179

grep a string between two single quotes using only grep function

Get a string between two single quotes using only grep function

 0x00000000: 00000000 0000000f 00320031 00340033 '........1.2.3.4.'

I want my output as ........1.2.3.4.

I tried grep -o '\'[^\']*'

but it is not working ?

Upvotes: 1

Views: 3848

Answers (1)

glenn jackman
glenn jackman

Reputation: 246799

bash does not allow you to embed single quotes inside a single quoted string. Not even escaped.

You need grep -o "'[^]'*"

If you want to exclude the leading single quote, and if you use GNU grep, then

grep -oP "(?<=').*?(?=')"

Upvotes: 4

Related Questions