Regex to pull out all words in apostrophes in a string


 
Thread Tools Search this Thread
Top Forums Programming Regex to pull out all words in apostrophes in a string
# 1  
Old 06-03-2011
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 09:38 AM..
# 2  
Old 06-03-2011
This line will generate the output you want:
Code:
awk -F "'" '{for (i=2;i<=NF;i+=2) {printf $i" "}; print ""}' file_with_text

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

# 4  
Old 06-03-2011
Code:
perl -lane '@arr = /\047(\w+)\047/g}{print for @arr' a

output :

Code:
 
ACTIVE
INACTIVE
DELETED

# 5  
Old 06-06-2011
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regex to identify unique words in a dictionary database

Hello, I have a dictionary which I am building for the Open Source Community. The data structure is as under HEADWORD=PARTOFSPEECH=ENGLISH MEANING as shown in the example below अ=m=Prefix signifying negation. अँहँ=ind=Interjection expressing disapprobation. अं=int=An interjection... (2 Replies)
Discussion started by: gimley
2 Replies

2. Shell Programming and Scripting

Printing apostrophes by using awk

Hello All, I would like to ask your kind help regarding the following query: I have this line: awk '$2>5 {print "File: "$1,$2}' I have got this output: File: zzzds 76 File: fd9ffh 58 File: gfh0dg 107 .... Could you please help me how to modify my line to get these outputs with... (5 Replies)
Discussion started by: Padavan
5 Replies

3. Shell Programming and Scripting

Grep with regex containing one string but not the other

Hi to you all, I'm just struggling with a regex problem and I'm pretty sure that I'm missing sth obvious... :confused: I need a regex to feed my grep in order to find lines that contain one string but not the other. Here's the data example: 2015-04-08 19:04:55,926|xxxxxxxxxx| ... (11 Replies)
Discussion started by: stresing
11 Replies

4. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

5. UNIX for Dummies Questions & Answers

Problems with deleting punctuation and apostrophes

Dear All, I have a file which I want to get the list of frequency of each word, ignoring list of stop words and now I have problems which punctuations and " 's ". what I am doing is: sed 's///g' file01.txt > file01-clear.txt cat file01-clear.txt | tr "" ""| tr ' ' '\012' |sort |uniq -c... (3 Replies)
Discussion started by: A-V
3 Replies

6. UNIX Desktop Questions & Answers

How to find that has a string and pull the record out of that file

Hello Experts !!! Have some trouble finding a solution for the problem mentioned below. Please help. Thanks, Lee. I have set of input files as below File1 MCMCNDD77 20100903:12:36:50 323-2322 BAC,MRP,NWER CKDJKJK838838 234 ... (4 Replies)
Discussion started by: OMLEELA
4 Replies

7. Shell Programming and Scripting

filtering out duplicate substrings, regex string from a string

My input contains a single word lines. From each line data.txt prjtestBlaBlatestBlaBla prjthisBlaBlathisBlaBla prjthatBlaBladpthatBlaBla prjgoodBlaBladpgoodBlaBla prjgood1BlaBla123dpgood1BlaBla123 Desired output --> data_out.txt prjtestBlaBla prjthisBlaBla... (8 Replies)
Discussion started by: kchinnam
8 Replies

8. Shell Programming and Scripting

using regex to get part of a string ?

Hi there, i wonder, is it possible to use regular expressions to partially select a string? I have a bunch of server names which look like this server1z-test server2z2 server45z-primary server13z3 I want to extract up to and including the 'z' in the server name, so for example ... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

9. UNIX for Dummies Questions & Answers

regex on first string in a variable.

Hi all, this is driving me nuts. I need to evaluate if a variable in a shell script has a heading s or m character e.g. s92342394 or m9233489 if so then I need to get rid of them. I'm quite familiar with PERL and could do it there in 3 mins but I have not found a decent way to do this in a shell.... (1 Reply)
Discussion started by: Endo
1 Replies

10. Shell Programming and Scripting

How to include a variable between apostrophes within a command

Hi. I'm trying to find some words within my directory and created a text file containing them which is read by my shell script: #!/bin/bash var=`cat words.txt` for i in $var; do echo $i find -type f -print0 | xargs -r0 grep -F '$i' done But it searches "$i" (dollar sign... (2 Replies)
Discussion started by: guarriman
2 Replies
Login or Register to Ask a Question