The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
double-quote inside double-quote indraf Shell Programming and Scripting 3 10-20-2008 06:53 AM
How to get rid of double quote in sed. anakiar Shell Programming and Scripting 6 07-28-2008 09:56 AM
Problem with double quote and string variable mattemp Shell Programming and Scripting 6 03-19-2008 01:21 AM
Escape Char for double quote navik_pathak Shell Programming and Scripting 1 01-05-2007 02:34 PM
single or double quote in SED asami Shell Programming and Scripting 2 07-17-2006 04:03 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-17-2009
vsairam vsairam is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 15
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 (permalink)  
Old 07-17-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Try:

Code:
awk '{if($0 ~ "\"") printf $0"\n" >> "file1";else printf $0"\n" >> "file2"}' inputfile

  #3 (permalink)  
Old 07-17-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Something Like this :


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

  #4 (permalink)  
Old 07-17-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,323

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

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0