Extracting the records which contains atleast one double quote(")


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting the records which contains atleast one double quote(")
# 1  
Old 07-17-2009
Extracting the records which contains atleast one double quote(")

Hi Experts,

I have a file with some of records contain double quotes ("). I need to write these records in separate file and have to delete the same records from the original file.

For Example:

Orginal File :
Code:
 
100000,abcd,CRED,MO
100001,"efgh",CRED
100002,ijkl,CRED,TX
100003,"mnop",CRED,TX
100004,qrstuv,CRED

After executing shell scripting it has to generate two files as below...

File 1 :
Code:
100000,abcd,CRED,MO
100002,ijkl,CRED,TX
100004,qrstuv,CRED

File 2 :
Code:
 
100001,"efgh",CRED
100003,"mnop",CRED,TX

Can you please help in this scenarios in shell scripting.


Next time use CODE-tags when post code, data or logs to enhance readability and to keep formatting like indention etc., ty.

Last edited by zaxxon; 07-17-2009 at 02:39 AM.. Reason: code tags
# 2  
Old 07-17-2009
Try:
Code:
awk '{if($0 ~ "\"") printf $0"\n" >> "file1";else printf $0"\n" >> "file2"}' inputfile

# 3  
Old 07-17-2009
Something Like this :

Code:
awk '$0 ~ /"/ {print >"File1";next} {print >"File2"}'  File_name.txt

# 4  
Old 07-17-2009
Code:
$> awk '/\"/ {print >> "file2"; next} {print >> "file1"}' infile
$> cat file1
100000,abcd,CRED,MO
100002,ijkl,CRED,TX
100004,qrstuv,CRED
$> cat file2
100001,"efgh",CRED
100003,"mnop",CRED,TX

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract delta records using with "comm" and "sort" commands combination

Hi All, I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file. comm -3 < sort file_old < sort file_new > new_file I am getting the below error: -ksh: sort: cannot open But if I do... (7 Replies)
Discussion started by: njny
7 Replies

2. Shell Programming and Scripting

Replacing all but the first and last double quote in a line with a single quote with awk

From: 1,2,3,4,5,This is a test 6,7,8,9,0,"This, is a test" 1,9,2,8,3,"This is a ""test""" 4,7,3,1,8,"""" To: 1,2,3,4,5,This is a test 6,7,8,9,0,"This; is a test" 1,9,2,8,3,"This is a ''test''" 4,7,3,1,8,"''"Is there an easy syntax I'm overlooking? There will always be an odd number... (5 Replies)
Discussion started by: Michael Stora
5 Replies

3. Shell Programming and Scripting

Replacing Double Quote in Double Quote incsv file

Hi All , We have source data file as csv file and since data could contain commas ,each attribute is quoted into double quotes.However problem is that some of the attributa data also contain double quotes which is converted to double double quote while creating csv file XLs data : ... (2 Replies)
Discussion started by: Shalini Badal
2 Replies

4. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

5. Shell Programming and Scripting

awk sub function "quote or slash"

I struggle to understand why its used slash / instead of doublequotes " in sub function of awk. This is taken from the manual of awksub(/USA/, "United States", "the USA and Canada") But this work alsosub("USA", "United States", "the USA and Canada") Is there any reason of why to select one... (2 Replies)
Discussion started by: Jotne
2 Replies

6. Shell Programming and Scripting

getting value between double quote

Can somebody supply me with a simple way to get a value between two double quotes? Example: input = ADR base is "/u01/app/oracle" output = /u01/app/oracle Thanks to all who answer (4 Replies)
Discussion started by: BeefStu
4 Replies

7. Shell Programming and Scripting

Regex in grep to match all lines ending with a double quote (") OR a single quote (')

Hi, I've been trying to write a regex to use in egrep (in a shell script) that'll fetch the names of all the files that match a particular pattern. I expect to match the following line in a file: Name = "abc" The regex I'm using to match the same is: egrep -l '(^) *= *" ** *"$' /PATH_TO_SEARCH... (6 Replies)
Discussion started by: NanJ
6 Replies

8. Shell Programming and Scripting

Records which are staring with double quote(") and a number

Hi Experts... I am trying to find out separting the records which are staring with double quote(") and a six digit number(ex: 012456,987654,etc) from a file. For example : Source File : "116462","SMITH CHEVR "164098","SIMPS "104498","SIMPSONVIL "Export lments" "Copyrts... (4 Replies)
Discussion started by: vsairam
4 Replies

9. Shell Programming and Scripting

double-quote inside double-quote

hey all, i made a simple .sh like this: echo "<style media="screen" type="text/css">@import url("main.css");</style>" but the output is: <style media=screen type=text/css>@import url(main.css);</style> i want to keep double-quotes, can anyone help me? thanks (3 Replies)
Discussion started by: indraf
3 Replies
Login or Register to Ask a Question