|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
Code:
echo $string | awk -F\' '{for(i=2;i<NF;i+=2)print $i}' |
|
#4
|
|||
|
|||
|
Code:
perl -lane '@arr = /\047(\w+)\047/g}{print for @arr' aoutput : Code:
ACTIVE INACTIVE DELETED |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|