I have a set of csv files (around 250), each having 300 to 500 records. I need to cut 2 or 3 columns from each file and store it to another one. I'm using ubuntu OS. Is there any way to do it in command or utility?
相关问题
- How to get the return code of a shell script in lu
- sqlyog export query result as csv
- Why doesn't php sleep work in the windows-subs
- Invoking Mirth Connect CLI with Powershell script
- Installing Pydev for Eclipse throws error
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- 为什么nfs在不同版本的Linux下安装的文件都不一样
- In IntelliJ IDEA, how can I create a key binding t
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- How to read local csv file in client side javascri
- Launch interactive SSH bash session from PHP
- Symfony : Doctrine data fixture : how to handle la
If you know that the column delimiter does not occur inside the fields, you can use cut.
You can use the shell buildin 'for' to loop over all input files.
If the fields might contain the delimiter, you ought to find a library that can parse CSV files. Typically, general purpose scripting languages will include a CSV module in their standard library.
If your fields contain commas or newlines, you can use a helper program I wrote to allow cut (and other UNIX text processing tools) to properly work with the data.
https://github.com/dbro/csvquote
This program finds special characters inside quoted fields, and temporarily replaces them with nonprinting characters which won't confuse the cut program. Then they get restored after cut is done.
lutz' solution would become:
If you used
ssconvert
to get the CSV you might try:Notice the TXT extension instead CSV, this way will use Gnumeric_stf:stf_assistant exporter instead of Gnumeric_stf:stf_csv, which let you use options (
-O
parameter). Otherwise you'll get a The file saver does not take options error. Pipe character is much more unlikely, but you might want to check before.Then you can rename it and do things like:
-O 'eol=unix separator=; format=preserve charset=UTF-8 locale=en_US transliterate-mode=transliterate quoting-mode=never'
.ssconvert
man page.