You are not logged in.

#1 2009-04-01 14:35:57

eldragon
Member
From: Buenos Aires
Registered: 2008-11-18
Posts: 1,029

using sed or awk to keep text within quotes

how would i accomplish this, i want to strip everything in a line and keep quoted text in within simple quotes: like this

'some text here'

would end up as

some text here

im lost due to the nature of single quotes

Offline

#2 2009-04-01 15:02:23

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: using sed or awk to keep text within quotes

echo "no print 1 'print 1' no print 2 'print 2' no print 3" | sed -n "s/[^']*'\([^']*\)'[^']*/\1/gp"

Offline

#3 2009-04-01 15:29:05

eldragon
Member
From: Buenos Aires
Registered: 2008-11-18
Posts: 1,029

Re: using sed or awk to keep text within quotes

Procyon wrote:
echo "no print 1 'print 1' no print 2 'print 2' no print 3" | sed -n "s/[^']*'\([^']*\)'[^']*/\1/gp"

thanks, i found it really difficult to escape the ' char big_smile this works ok

just for anyone caring. i needed to have a random thumbnail on my desktop with my favorite pics wink

Last edited by eldragon (2009-04-01 15:30:51)

Offline

Board footer

Powered by FluxBB