Solved

bash: convert huge 2 col csv file to 1 col txt

Posted on 2013-12-02
3
323 Views
Last Modified: 2013-12-03
Hi

Can you help me with the command to convert a huge csv file to a txt file.

CSV:

"a.bc","12.3"
"er.4","j.43"
"4rt.234,"as.df"

TXT should bee like this (1st col from csv without double quotes)

a.bc
er.4
4rt.234

Thanks!
0
Comment
Question by:netslt
3 Comments
 
LVL 14

Accepted Solution

by:
jb1dev earned 500 total points
ID: 39690820
I assume that last line should be:
"4rt.234","as.df"

You can use
cat input.csv | sed 's/",".*//' | sed 's/"//'
0
 
LVL 19

Expert Comment

by:xterm
ID: 39691447
If you're just wanting to discard the quotes from the first value, and the second value entirely which is the way I understand it, then do this:

cat input.csv| cut -d, -f1 | tr -d '"' > input.txt

Open in new window


This way it will not matter if that missing quote pointed out by jb1dev is in some of the real input csv, or just a typo in the question - it will still do what you want.
0
 

Author Closing Comment

by:netslt
ID: 39691907
jb1dev has what I was looking for - works perfectly!

(xterm might also be right, have not tried....)

Thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AWS- KeepAlived notify script not working 23 79
powershell code to list items in dropdown 6 57
Rate limit for DNS queries 7 72
Run DOS2UNIX and then execute the command 21 70
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now