使用shell命令执行字符操作
我需要将从 Mac Excel 2011 导出的 CSV 文件转换为 CMS 识别的可导入格式(解决方案不应相关,但导入格式适用于 Drupal Feeds 模块,尽管是目标)。
目前为了做到这一点,我需要在 Vim 中执行以下操作:
:%s/\r/\r/g
:w ++enc=utf8
这基本上意味着:
- 将回车符转换为某种通用格式
- 最初在 Excel 导出它们时,回车符由
^M
表示 - Vim 命令
:%s/\r/\r/g
将它们全部转换为 CMS 识别为回车符的格式
- 最初在 Excel 导出它们时,回车符由
- 将字符编码转换为 UTF8。
- 最初导出时,字符集是
ASCII Extended
或类似的字符集。
- 最初导出时,字符集是
理想情况下,需要在作为导入的一部分上传文件时触发该过程,这意味着 PHP 将触发该过程,无论这是否对该过程有任何影响。不过,此时我觉得将解决方案作为 shell 脚本或类似的东西来处理会更舒服,但是如果我能弄清楚如何将其挂接到 Drupal 7 Feeds 中,那么 PHP 解决方案当然是受欢迎的。
I need to convert a CSV file exported from Mac Excel 2011 to an importable format recognized by a CMS (the solution should not be related, however the import format is for Drupal Feeds module, although the target).
In order to do this currently I need to perform the following operations in Vim:
:%s/\r/\r/g
:w ++enc=utf8
Which basically means:
- Convert carriage returns to some sort of universal format
- Initially as Excel exports them, the carriage return character is represented by
^M
- the Vim command
:%s/\r/\r/g
converts them all to a format the CMS recognizes as a carriage return
- Initially as Excel exports them, the carriage return character is represented by
- Convert the character encoding to UTF8.
- As exported initially, the character set is
ASCII Extended
or something similar.
- As exported initially, the character set is
Ideally this process will need to be triggered upon uploading the file as part of the import, which means PHP will trigger the process, whether that has any bearing on the process. However I feel more comfortable at this point handling the solution as a shell script or something similar, but of course PHP solutions are welcome if I can figure out how to hook it into Drupal 7 Feeds.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些未经测试的代码:
用法:
Some untested code:
Usage: