将.txt文件转换为.csv,并在bash中包含标题 [英] Convert .txt file to .csv with header in bash

查看:178
本文介绍了将.txt文件转换为.csv,并在bash中包含标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.txt如下:

2013-04-10;248179;5431;5375.30€;1.49
..
..
..

我需要一个.csv文件a标题:

I need a .csv file with a Header:

Date       Visit   Login  Euro      Rate
2013-04-10 248179  5431   5375.30€  1.49
..         ..      ..     ..        ..
..         ..      ..     ..        ..

有什么方法可以用BASH得到这个结果?

Is there a way to get this result with BASH?

推荐答案

strong>您的字段不包含任何有趣的商家:

This should do it, if your fields don't contain any funny business:

(echo "Date;Visit;Login;Euro;Rate" ; cat file.txt) | sed 's/;/<tab>/g' > file.csv

您只需在bash(^ V TAB)中键入一个标签。如果你的版本的sed支持它,你可以写 \t 而不是一个文字选项卡。

You'll just have to type a tab literally in bash (^V TAB). If your version of sed supports it, you can write\t instead of a literal tab.

这篇关于将.txt文件转换为.csv,并在bash中包含标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆