×
UNIX.COM Login
Username:
Password:  
Show Password






👤


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

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-14-2017
preema preema is offline
Registered User
 
Join Date: May 2017
Last Activity: 1 March 2018, 6:28 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 08:55 AM.. Reason: Added CODE/ICODE tags
Sponsored Links
    #2  
Old 12-14-2017
jgt's Unix or Linux Image
jgt jgt is offline Forum Advisor  
Registered User
 
Join Date: Apr 2007
Last Activity: 16 July 2018, 7:53 AM EDT
Location: 44.21.48N 80.50.15W
Posts: 2,077
Thanks: 2
Thanked 296 Times in 271 Posts
there was a similar discussion recently.

Last edited by jgt; 12-14-2017 at 09:00 AM.. Reason: spelling
The Following User Says Thank You to jgt For This Useful Post:
RudiC (12-14-2017)
Sponsored Links
    #3  
Old 12-14-2017
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 16 July 2018, 10:59 AM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,485
Thanks: 145
Thanked 209 Times in 184 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 (01-18-2018)
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 08:18 AM
Removing commas within semicolon in a flat file r_t_1601 Shell Programming and Scripting 31 06-24-2009 11:51 AM
Removing commas within semicolon in a flat file r_t_1601 Shell Programming and Scripting 10 06-16-2009 06:52 AM
Padding zeros after removing commas in file pranag21 HP-UX 1 11-09-2005 09:22 PM
removing commas from text file hcclnoodles UNIX for Dummies Questions & Answers 6 03-26-2003 03:43 PM



All times are GMT -4. The time now is 09:40 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.