简体   繁体   English

我有一个具有两种不同日期值格式的csv文件,希望它们采用任何单一格式

[英]I have a csv file with two different formats of date value, want them to be in any single format

My CSV file looks like this 我的CSV文件如下所示

id       date
1602    11/23/2015 14:10
1602    11/23/2015 22:45
1602    18/10/2011 09:19:46 AM
1702    18/10/2011 09:07:33 AM
1863    18/10/2011 09:07:35 AM
1436    18/10/2011 09:07:36 AM

I'm looking for output like 我正在寻找类似的输出

id       date
1602    11/23/2015 14:10
1602    11/23/2015 22:45
1602    10/18/2011 09:19:46 AM
1702    10/18/2011 09:07:33 AM
1863    10/18/2011 09:07:35 AM
1436    10/18/2011 09:07:36 AM

I'm not sure why you are making this so much more difficult than it is. 我不确定为什么您要比现在做起来困难得多。 It seems that all you are actually doing is (1) getting rid of the first line of the CSV file; 看来您实际要做的只是(1)删除CSV文件的第一行; (2) tossing out any quotation marks; (2)扔掉任何引号; (3) mapping sets of spaces/tabs into single spaces; (3)将空格/制表符集映射为单个空格; and (4) mapping newlines to spaces. (4)将换行符映射到空格。

SO . 所以 . . how about the following? 接下来呢? (I assume the data comes from standard input.) (我假设数据来自标准输入。)

sed 1d | sed 1天| tr -d /\\"/ | tr -s "/[ \\010\\012]/ /" tr -d / \\“ / | tr -s” / [\\ 010 \\ 012] / /“

The 'sed' deletes the first line; “ sed”删除第一行; the first 'tr' strips quotation marks; 第一个'tr'去除引号; the second 'tr' maps runs of spaces, tabs, and/or newlines to single spaces (\\010 and \\012 are the octal codes for ASCII TAB and ASCII NL, respectively). 第二个'tr'将空格,制表符和/或换行符映射到单个空格(\\ 010和\\ 012分别是ASCII TAB和ASCII NL的八进制代码)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有两种不同类型的用户表,我想在Hibernate的单个查询中检查移动重复 - I have two different type of user table and I want to check mobile duplication in single query in Hibernate 如何在两种不同的文件格式上运行单元测试? - How do I run unit tests on two different file formats? 使用GSON反序列化两种不同的日期格式 - deserialize two different date formats with GSON 比较两个不同格式的日期对象 - comparing two date objects of different formats 两个Java日期具有不同的格式 - Two Java Dates have Different Formats 我想用每行不同的值更新CSV文件,尽管代码返回了相同的值 - I want to update CSV file with a different value for each line, code is returning the same value though 单个正则表达式具有CSV以及xlsx文件格式 - Single regular Expression to have CSV as well as xlsx file format 尽可能动态地(许多不同的格式)从 a.csv 文件中解析日期或日期时间字符串? - Parsing Date or DateTime Strings out of a .csv file as dynamically (many different formats) as possible? 我有一个日期(字符串),格式为dd-mon-yyyy,我想将此日期与系统日期进行比较 - I have a date in(string) in dd-mon-yyyy format and I want to compare this date with system date 我在字符串中有日期我想将其转换为日期格式但我收到了错误 - I have date in string i want to convert it into date format but i got an error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM