Extract values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract values
# 1  
Old 11-19-2013
Extract values

hi

I have a line as given below. I need to match "COLUMN_NAME" and get the every third value ie words in between quotes completely (' ')


Code:
Sample Input - 
COLUMN_NAME Like '%value%' Or COLUMN_NAME Like '%value%' Or COLUMN_NAME Like '%value value%' Or COLUMN_NAME Like '%value%' OR COLUMN_NAME Like '% value%' OR COLUMN_NAME Like '%value %' OR COLUMN_NAME Like 'value' Or COLUMN_NAME Like '%value%' Or COLUMN_NAME LIKE ' value' Or COLUMN_NAME LIKE 'value '

Code:
Sample Output - 
COLUMN_NAME '%value%'
COLUMN_NAME '%value%'
COLUMN_NAME '%value value%'
COLUMN_NAME '%value%'
COLUMN_NAME '% value%'
COLUMN_NAME '%value %'
COLUMN_NAME 'value'
COLUMN_NAME '%value%'
COLUMN_NAME ' value'
COLUMN_NAME 'value '

Thanks in advance.

Moderator's Comments:
Mod Comment Please stop posting in the AIX forum that which in no way related to AIX. Thanks.

Last edited by Scott; 11-19-2013 at 10:18 AM.. Reason: Moved thread; Not an AIX-specific question
# 2  
Old 11-19-2013
Using perl:
Code:
$ perl -lne 'while(/(COLUMN_NAME) Like ('\''.*?'\'')/gi){print "$1 $2"}'  file
COLUMN_NAME '%value%'
COLUMN_NAME '%value%'
COLUMN_NAME '%value value%'
COLUMN_NAME '%value%'
COLUMN_NAME '% value%'
COLUMN_NAME '%value %'
COLUMN_NAME 'value'
COLUMN_NAME '%value%'
COLUMN_NAME ' value'
COLUMN_NAME 'value '


Last edited by Subbeh; 11-19-2013 at 11:04 AM..
# 3  
Old 11-19-2013
Try
Code:
awk     '       {for (i=1; i<NF-1; i++) 
                   if ($i == "COLUMN_NAME")     {printf "%s%s%s", $i, FS, $(i+=2)
                                                 if ($i!=/^\x27.*\x27$/) printf "%s%s", FS, $(i+1)
                                                 printf "\n"}
                }
        ' file

# 4  
Old 11-19-2013
Try :

Code:
$ awk 'gsub(/^[[:space:]]|[Ll][Ii][Kk][eE]/,x)' RS="Or|OR" file
COLUMN_NAME  '%value%' 
COLUMN_NAME  '%value%' 
COLUMN_NAME  '%value value%' 
COLUMN_NAME  '%value%' 
COLUMN_NAME  '% value%' 
COLUMN_NAME  '%value %' 
COLUMN_NAME  'value' 
COLUMN_NAME  '%value%' 
COLUMN_NAME  ' value' 
COLUMN_NAME  'value '

# 5  
Old 11-19-2013
Using GNU sed:
Code:
sed 's#\(COLUMN_NAME\)\([ ][^ ]*[ ]\)#\1 #g;s#\([ ][^ ]*[ ]\)\(COLUMN_NAME\)#\n\2#g' file

# 6  
Old 01-29-2014
Hello,

Following may also help.


Code:
awk 'gsub(/O[rR] /,"\n")1' file_name

Output will be as follows.

Code:
Sample Input -
COLUMN_NAME Like '%value%'
COLUMN_NAME Like '%value%'
COLUMN_NAME Like '%value value%'
COLUMN_NAME Like '%value%'
COLUMN_NAME Like '% value%'
COLUMN_NAME Like '%value %'
COLUMN_NAME Like 'value'
COLUMN_NAME Like '%value%'
COLUMN_NAME LIKE ' value'
COLUMN_NAME LIKE 'value '




Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract values only for certain tags

Hi Please I need help on extracting values, of certain tagsMSISDN:, and IMSI: in the following text file entryDS: 1 nodeId: 11 MSISDN: 258827475309 IMSI: 643012111658984 NAM: 0 CDC: 41 IMEISV:: U3URIGF2hoc= AUTHINFO: 0 TSMO:... (16 Replies)
Discussion started by: fretagi
16 Replies

2. Shell Programming and Scripting

Extract rows with different values at 2 columns

Hallo, I would need to extract only rows which has different value in the second and third column. Thank you very much for any advices Input: A 0 0 B 0 1 C 1 1 D 1 3 Output B 0 1 D 1 3 (4 Replies)
Discussion started by: kamcamonty
4 Replies

3. Shell Programming and Scripting

Is it possible to extract these values from the output

Hi, I would like to search based of "java" and "-Dplatform.home=" and store these two values in bash variables. ps -xef | grep <pid> wlsuser 15160 15144 0 Feb 20 ? 17:27 /app1/jdk150_07/bin/IA64N/java -server -Xms1536m -Dplatform.home=/app1/bea/weblogic92... (13 Replies)
Discussion started by: mohtashims
13 Replies

4. Shell Programming and Scripting

Extract values of duplicate keys

I have two questions that are related, so it would be great if you can help me with both! Question1: I have a file A that looks like this: a x b y b z c w I want to get something like: a x b y; z c w Given that a,b,c has no spaces. But the other letters might contain spaces. ... (2 Replies)
Discussion started by: Viernes
2 Replies

5. Shell Programming and Scripting

extract key values

I am parsing a log with key values spread all over in the following fashion: TEST 1 SCHEME 12 SET EMPTY VARLEN SET TEST 1201 PARAM1 EMTY PARAM2 SET SCHEME 12 REFRESH TEST 8 I need to extract test number, my result should be 1 1201 8 I use awk for processing this log and use... (4 Replies)
Discussion started by: migurus
4 Replies

6. Shell Programming and Scripting

Awk extract a range of values

Hi Input 10 131 11 179 11 170 20 142 20 131 20 144 21 178 22 155 22 196 23 144 23 184 24 194 24 191 24 218 25 167 25 131 26 189 (6 Replies)
Discussion started by: genehunter
6 Replies

7. Shell Programming and Scripting

to extract specific values twice in a file

Hi Friends, I have a file with the following values.. xyz.txt,12345.xml abc.txt,04567.xml cde.txt,12134.xml I would like to extract all the 2nd column values twice as shown in the example like 12345,12345.xml 04567,04567.xml 12134,12134.xml Please advice!! In the formus one of... (7 Replies)
Discussion started by: techmoris
7 Replies

8. Shell Programming and Scripting

Extract Values from CSV

Hi, I need to extract values from a CSV file based on some conditions as explained below: File format details: 1. each set starts with AAA only 2. number of columns is fixed 3. number of rows per set may vary (as they are having different CCC rows) Now, i need to extract 3rd column of... (3 Replies)
Discussion started by: prvnrk
3 Replies

9. Shell Programming and Scripting

Extract XML Element Values

I have a rather large file with XML-style content. Each line contains one full XML entry. For example: 1:<Message><DNIS>1234</DNIS><UCID>3456</UCID><TransferGroup>XYZXYZ</TransferGroup></Message> 2:<Message><DNIS>9999</DNIS><UCID>2584</UCID><TransferGroup>ABCABC</TransferGroup></Message>... (1 Reply)
Discussion started by: sharpi03
1 Replies

10. Shell Programming and Scripting

how to extract values b/w two delimiters

Hi, Please help me to extrat values b/w two delimiters. $ echo $abc i want to extract the value 12345 b/w %. (5 Replies)
Discussion started by: tsaravanan
5 Replies
Login or Register to Ask a Question