Solved

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

Posted on 2013-12-02
3
316 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

708 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

15 Experts available now in Live!

Get 1:1 Help Now