如何使用sed删除文件中的第n个字符 [英] How to delete nth character in a file using sed

查看:62
本文介绍了如何使用sed删除文件中的第n个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须删除大文件中第n个字符. Vi 会挂起这么大的文件.我知道 sed 中会有一些简单的命令可以做到这一点.但是,我发现很难理解 sed 脚本及其表达式.

I have to delete a character at nth position in a big file. Vi hangs for such a big file. I know there will be some simple command in sed to do so. But, I find it difficult to understand sed scripts and its expressions.

我拥有的文件内容如下:

The file I have has content like:

{查询":锁定和",时间戳":"2012-12-28T00:00:00.045000 + 00:00","productId":322506} ,, {"query":"Velvet Crush","timestamp":"2012-12-28T00:00:00.045000 + 00:00","productId":134363}

{"query": "Lock and", "timestamp": "2012-12-28T00:00:00.045000+00:00", "productId": 322506},,{"query": "Velvet Crush", "timestamp": "2012-12-28T00:00:00.045000+00:00", "productId": 134363}

我必须删除多余的 ,即该文件中第 130405 个字符.我如何使用sed实现这一目标.

I have to delete that extra , which is 130405 th character in that file. How do I use sed to achieve this.

现在,我希望将所有双逗号替换为一个.该怎么办?

Now I wish to replace all aoocurances of double comma by a single one in-place. How can that be done?

推荐答案

sed -i's/.//130405'FILE

这将在位置( -i )上编辑文件( FILE ),删除位置 130405处的任何字符(.).

This edits the file (FILE) in place (-i), deleting any character (.) at position 130405

这篇关于如何使用sed删除文件中的第n个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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