[英]Convert .CSV file to .txt file using bash
I have a CSV with lots of lines delimited by comma.我有一个 CSV 文件,其中有很多行以逗号分隔。 I have to convert it to text.
我必须将其转换为文本。
66012523,39,Feb 02 2015 05:19AM,
66012523,39,Feb 02 2015 09:53AM,
66012523,39,Feb 02 2015 01:38PM,
I used command cp source.csv destination.csv
and also cat source.csv > destination.txt
but it does output in the same format witch each line coming in new one.我使用命令
cp source.csv destination.csv
和cat source.csv > destination.txt
但它确实以相同的格式输出,每一行都是新的。 It just gets appended together.它只是被附加在一起。 It outputs like
它输出像
66012523,39,Feb 02 2015 05:19AM,66012523,39,Feb 02 2015 09:53AM,66012523,39,Feb 02 2015 01:38PM
How do I make them to output each line in newline.如何让它们以换行符输出每一行。 Please help.
请帮忙。
I hypothesise that the first block in your question is what you WANT, and what you actually HAVE is我假设您问题中的第一个块是您想要的,而您实际上拥有的是
66012523,39,Feb 02 2015 05:19AM,66012523,39,Feb 02 2015 09:53AM,66012523,39,Feb 02 2015 01:38PM
So what you want to do, I hypothesise, is split this up into separate lines.所以你想要做的,我假设,是把它分成单独的行。
Am I right?我对吗?
This is a bit rough-and-ready but it works.这有点粗糙,但它有效。 Relies on each group ending "M," and there being no other "M,"s in the text - which there aren't but I wouldn't call it robust.
依赖于以“M”结尾的每个组,并且文本中没有其他“M”——没有但我不会称之为健壮。
sed s/M,/'\n'/g source.csv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.