Go Back   The UNIX and Linux Forums > Top Forums > Programming


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-03-2011
Registered User
 
Join Date: Jun 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Regex to pull out all words in apostrophes in a string

Hi,

I have string like this:

CHECK (VALUE::text = ANY (ARRAY['ACTIVE'::character varying::text, 'INACTIVE'::character varying::text, 'DELETED'::character varying::text]))

and I am trying to get out the words in apostrophes (').
In this case"ACTIVE INACTIVE DELETE"

Also the array may consist of one or more words (in given example 3). Also instead of word it can be only one LETTER.

And test I am trying to get ridge in this example can also vary. So the apostrophes are the only thing to consider I guess.

Can someone help me?

Last edited by neptun79; 06-03-2011 at 08:38 AM..
Sponsored Links
    #2  
Old 06-03-2011
Registered User
 
Join Date: Jun 2011
Posts: 18
Thanks: 0
Thanked 2 Times in 2 Posts
This line will generate the output you want:

Code:
awk -F "'" '{for (i=2;i<=NF;i+=2) {printf $i" "}; print ""}' file_with_text

Sponsored Links
    #3  
Old 06-03-2011
Moderator
 
Join Date: Feb 2007
Location: The Netherlands
Posts: 7,505
Thanks: 73
Thanked 474 Times in 453 Posts

Code:
echo $string | awk -F\' '{for(i=2;i<NF;i+=2)print $i}'

    #4  
Old 06-03-2011
Registered User
 
Join Date: May 2011
Location: India
Posts: 124
Thanks: 2
Thanked 29 Times in 29 Posts

Code:
perl -lane '@arr = /\047(\w+)\047/g}{print for @arr' a

output :


Code:
 
ACTIVE
INACTIVE
DELETED

Sponsored Links
    #5  
Old 06-06-2011
Registered User
 
Join Date: Jun 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you for all your replies. I will go with the awk one since it is faster. One more question. Since you provided awk and perl solution, does it mean that this cannot be done in sed?
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find that has a string and pull the record out of that file OMLEELA UNIX Desktop for Dummies Questions & Answers 4 11-04-2010 06:32 PM
filtering out duplicate substrings, regex string from a string kchinnam Shell Programming and Scripting 8 06-15-2010 05:14 PM
using regex to get part of a string ? hcclnoodles Shell Programming and Scripting 4 08-24-2009 04:49 PM
regex on first string in a variable. Endo UNIX for Dummies Questions & Answers 1 09-03-2008 07:28 AM
How to include a variable between apostrophes within a command guarriman Shell Programming and Scripting 2 03-16-2007 11:44 AM



All times are GMT -4. The time now is 08:20 PM.