用sed删除Linux中文本文件任意行的前五个字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3795512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:38:28  来源:igfitidea点击:

Delete the first five characters on any line of a text file in Linux with sed

linuxunixsed

提问by JBeg

I need a one-liner to remove the first five characters on any line of a text file. How can I do that with sed?

我需要一个单行来删除文本文件任何行上的前五个字符。我怎样才能用 sed 做到这一点?

采纳答案by Phil

sed 's/^.....//'

means

方法

replace ("s", substitute) beginning-of-line then 5 characters (".") with nothing.

替换 ("s", 替换) 行首然后 5 个字符 (".") 没有任何内容

There are more compact or flexible ways to write this using sed or cut.

使用 sed 或 cut 有更紧凑或更灵活的方式来编写它。

回答by Ignacio Vazquez-Abrams

sed 's/^.\{,5\}//' file.dat

回答by Greg Hewgill

Use cut:

使用cut

cut -c6-

This prints each line of the input starting at column 6 (the first column is 1).

这将从第 6 列(第一列是 1)开始打印输入的每一行。

回答by ghostdog74

awk '{print substr(##代码##,6)}' file

回答by Gopi

sed 's/^.\{,5\}//' file.datworked like a charm for me

sed 's/^.\{,5\}//' file.dat对我来说就像一种魅力