LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-23-2015, 08:10 AM   #1
ksuresh.vpk
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Rep: Reputation: Disabled
Convert .csv to .psv


How to convert CSV file to PSV file without affecting comma inbetween the quotes
 
Old 12-23-2015, 08:20 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,329

Rep: Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026
Quote:
Originally Posted by ksuresh.vpk View Post
How to convert CSV file to PSV file without affecting comma inbetween the quotes
Read the "Question Guidelines" link in my posting signature.

Unless you provide actual, useful DETAILS, there's little we can tell you. You don't tell us version/distro of Linux, provide a sample of the data, or show us what YOU have done/tried on your own. Could be a simple matter of sed or grep, but we have no idea because of the lack of details.
 
1 members found this post helpful.
Old 12-23-2015, 08:32 AM   #3
ksuresh.vpk
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Sorry for not providing clear details.

I am using CentOS 6.6.

Original record :

3ds.com,Dassault Systemes,"900, Chelmsford Street",Lowell,MA,1851,US,2033745118,Noreen,Klinga,"Senior Specialist,marketing,marketing Programs",noreen.klinga@3ds.com,Marketing - General,Staff,Business Services - Other,1887,1000000,Domain Confirmed

Required :

3ds.com|Dassault Systemes|900, Chelmsford Street|Lowell|MA|1851|US|2033745118|Noreen|Klinga|Senior Specialist,marketing,marketing Programs|noreen.klinga@3ds.com|Marketing - General|Staff|Business Services - Other|1887|1000000|Domain Confirmed

I have tried

sed -i 's/,/|/g' file.csv

getting the ouput

3ds.com|Dassault Systemes|"900| Chelmsford Street"|Lowell|MA|1851|US|2033745118|Noreen|Klinga|"Senior Specialist|marketing|marketing Programs"|noreen.klinga@3ds.com|Marketing - General|Staff|Business Services - Other|1887|1000000|Domain Confirmed

help me to solve this.
 
Old 12-23-2015, 08:54 AM   #4
ksuresh.vpk
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
I am using CentOS 6.6.

Ex : a,b,c,"d,e,f",g,h,"i,j",k

Req : a|b|c|d,e,f|g|h|i,j|k

I have tried

sed -i 's/,/|/g' file.csv

but the output is

a|b|c|d|e|f|g|h|i|j|k|

How to escape double quote.
 
Old 12-23-2015, 09:55 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,769

Rep: Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052
I would suggest using awk, perl or ruby for such a task. awk being the simplest you can have a look at the FPAT example found here
 
Old 12-23-2015, 10:13 AM   #6
ksuresh.vpk
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
sorry, this is not helpful
 
Old 12-23-2015, 10:36 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,769

Rep: Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052
Why not? It produced this data for me:
Code:
$ echo 'a,b,c,"d,e,f",g,h,"i,j",k' | awk '<other stuff>' FPAT="([^,]+)|(\"[^\"]+\")"
a|b|c|"d,e,f"|g|h|"i,j"|k
 
1 members found this post helpful.
Old 12-23-2015, 11:16 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,329

Rep: Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026
Quote:
Originally Posted by ksuresh.vpk View Post
sorry, this is not helpful
Really? Grail handed you a ready-made solution, which works fine, based on your examples. How, exactly, is this not helpful?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert to csv using sed. vipinsqa Linux - Newbie 13 11-14-2014 12:45 PM
convert log file to CSV ablanco20 Linux - Newbie 3 07-23-2013 03:21 PM
Perl convert csv to xls hawk__0 Programming 3 09-16-2009 10:13 AM
[SOLVED] Convert CSV to Tab imkornhulio Programming 7 11-15-2008 08:20 PM
Convert into CSV file say_hi_ravi Programming 4 07-17-2008 04:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration