在 Linux 中,使用 sed 删除文本文件中任何一行上的前五个字符

我需要一行程序来删除文本文件中任何一行的前五个字符。我怎么能用 sed 做到呢?

152565 次浏览
sed 's/^.\{,5\}//' file.dat

Use cut:

cut -c6-

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

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

means

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

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