Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Removing commas from CSV file

UNIX for Beginners Questions & Answers


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-14-2017   -   Original Discussion by preema
preema's Unix or Linux Image
preema preema is offline
Registered User
 
Join Date: May 2017
Last Activity: 18 January 2018, 6:40 AM EST
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Removing commas from CSV file

Hi
I'm creating a sh script to generate a csv file. The CSV contains the values from a sql table.
The content looks this:



Code:
 a,b,c,c2,c3,,,,,,,,,,,d,e

I have some code that can separate the fields using the comma as delimiter, but some values actually contain commas, such as c,c2,c3,,,,,,,,,

This field needs to be taken as one field and the trailing commas after c3 must be removed.
Can anybody please help in doing this ?

Thanks in advance!!

Last edited by rbatte1; 12-14-2017 at 09:55 AM.. Reason: Added CODE/ICODE tags
Sponsored Links
    #2  
Old Unix and Linux 12-14-2017   -   Original Discussion by preema
jgt's Unix or Linux Image
jgt jgt is offline Forum Advisor  
Registered User
 
Join Date: Apr 2007
Last Activity: 19 January 2018, 8:00 AM EST
Location: 44.21.48N 80.50.15W
Posts: 2,029
Thanks: 2
Thanked 278 Times in 260 Posts
there was a similar discussion recently.

Last edited by jgt; 12-14-2017 at 10:00 AM.. Reason: spelling
The Following User Says Thank You to jgt For This Useful Post:
RudiC (12-14-2017)
Sponsored Links
    #3  
Old Unix and Linux 12-14-2017   -   Original Discussion by preema
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 17 January 2018, 9:31 AM EST
Location: Within two miles of a Dunkin donuts.
Posts: 2,474
Thanks: 137
Thanked 204 Times in 179 Posts
Since you are creating the file, why not use a different delimiter than the comma? Semi-colon, pipe, tilde are all delimiters I have used to separate fields. Then just alter the other program to know the different delimiter.
The Following User Says Thank You to joeyg For This Useful Post:
preema (1 Day Ago)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To Add extra commas to a CSV file. chillblue UNIX for Dummies Questions & Answers 12 07-05-2012 09:18 AM
Removing commas within semicolon in a flat file r_t_1601 Shell Programming and Scripting 31 06-24-2009 12:51 PM
Removing commas within semicolon in a flat file r_t_1601 Shell Programming and Scripting 10 06-16-2009 07:52 AM
Padding zeros after removing commas in file pranag21 HP-UX 1 11-09-2005 10:22 PM
removing commas from text file hcclnoodles UNIX for Dummies Questions & Answers 6 03-26-2003 04:43 PM



All times are GMT -4. The time now is 05:12 PM.