Extract data based on 2nd colume having double quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract data based on 2nd colume having double quotes
# 1  
Old 06-14-2013
Extract data based on 2nd colume having double quotes

i want extract where the 2nd column having "3" or "7".
Based on the forums tried like this but it is not working

Code:
awk -F"," '$2=3;$2=7 {print}' filename

Code:
Source 
"1","2","3","4"
"1","3","3","4"
"1","7","3","4"
"1","8","3","4"
"1","2","3","4"
"1","2","3","4"

Output :


"1","3","3","4"
"1","7","3","4"


Thanks
- Onesuri
# 2  
Old 06-14-2013
Code:
$ awk -F"," -v qt='"' '$2==qt 3 qt || $2==qt 7 qt ' file
"1","3","3","4"
"1","7","3","4"

# 3  
Old 06-14-2013
Code:
awk -F, '$2~/"(3|7)"/' file
"1","3","3","4"
"1","7","3","4"

Code:
awk -F, '$2~/"3"|"7"/' file

Code:
awk -F, '$2~/"[37]"/' file


Last edited by Jotne; 06-14-2013 at 04:17 AM.. Reason: Added "" to get correct result
# 4  
Old 06-14-2013
Code:
awk -F, '$2=="\"3\"" || $2=="\"7\""' file

or
Code:
awk -F'",?"?' '$3==3||$3==7' file

or
Code:
awk -F\" '$4==3||$4==7' file


--
@Jotne, that should be /"(3|7)"/ or /"[37]"/ for your first and your last option, no?

Last edited by Scrutinizer; 06-14-2013 at 04:04 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 06-14-2013
Code:
awk -F '","' '$2==3 || $2==7' file

OR
Code:
egrep '^.....(3|7)"' file


Last edited by pamu; 06-14-2013 at 04:25 AM..
# 6  
Old 06-14-2013
Quote:
@Jotne, that should be /"(3|7)"/ or /"[37]"/ for your first and your last option, no?
Yes, it will pick wrong if number is larger(more numbers), corrected

Some more variation
awk -F, '{split($2,a,"\"")} a[2]==3 || a[2]==7'

@pamu
awk -F '","' '$2==3 || $2==7' file
Is not a good option if you later like first or last field.

Last edited by Jotne; 06-14-2013 at 04:23 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace double quotes inside the string data for all the columns

Please use code tags Hi, I have input data is below format and n of column in the multiple flat files. the string data has any double quotes(") values replaced to double double quotes for all the columns{""). Also, my input flat file each column string data has carriage of new line too.... (14 Replies)
Discussion started by: SSrini
14 Replies

2. Shell Programming and Scripting

Extract multiple columns base on double quotes as delimiter

Hi All, I have my data like below "1","abc,db","hac,aron","4","5" Now I need to extract 1,2,4th columns Output should be like "1",abc,db","4" Am trying to use cut command but not able to get the results. Thanks in advance. (4 Replies)
Discussion started by: weknowd
4 Replies

3. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

4. Shell Programming and Scripting

Skip the delimiter with in double quotes and count the number of delimiters during data extract

Hi All, I'm stuck-up in finding a way to skip the delimiter which come within double quotes using awk or any other better option. can someone please help me out. Below are the details: Delimited: | Sample data: 742433154|"SYN|THESIS MED CHEM PTY.... (2 Replies)
Discussion started by: BrahmaNaiduA
2 Replies

5. Shell Programming and Scripting

Handling embedded double quotes within column data

I have a text file where each field is enclosed in double quotes and separated by a comma. But in certain rows we have embedded double quotes within column data For e.g """TRUSPICE CENTRE"" CLAYTON AU" The above value is for a single column but there are embedded quotes within... (2 Replies)
Discussion started by: abhilashnair
2 Replies

6. Shell Programming and Scripting

Extracting data from between double quotes

Need assistance , Below is the data between double code . </td><td><a href="geavg.t00z.pgrb2af18">geavg.t00z.pgrb2af18</a> Below commands gives me the result but i want everything in one command using single nawk nawk -v RS="< href" -F">" '/t00z/ { print $1 }' ucar.output | nawk -F... (10 Replies)
Discussion started by: ajayram_arya
10 Replies

7. Shell Programming and Scripting

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

8. Shell Programming and Scripting

Extract data based on position

The file has record length 200. And i have 100 search strings which are ten digits of character from 1 to 10 characters all of them are unique, they need to searched in a file. Please help me to pull the records based on position (say from 1-10). test data 1FAHP2DW0BG115206RASHEED ... (6 Replies)
Discussion started by: zooby
6 Replies

9. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

10. Shell Programming and Scripting

PERL, extract value between double quotes

I know this is probably much simplier than I am making but I need some help please. I have a data file that contains a value on the first line between double quotes ("00043"). I need to assign the value between the first set quotes to a variable in my perl script for comparison analysis. Also,... (6 Replies)
Discussion started by: methos
6 Replies
Login or Register to Ask a Question