简体   繁体   English

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

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

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做到这一点?

Use cut : 使用cut

cut -c6-

This prints each line of the input starting at column 6 (the first column is 1). 这将打印从第6列开始的每行输入(第一列为1)。

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有更紧凑或灵活的方法来编写它。

sed 's/^.\{,5\}//' file.dat
awk '{print substr($0,6)}' file

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM