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?
4 Answers
-
2Here, cut has a better performance than sed, but I got problems when used on utf-8 encoded characters.– PSchwedeNov 16, 2017 at 10:13
-
4Just to elaborate on @PSchwede's comment, GNU
cuttreats all characters as bytes even when you use the-coption. GNUcutdoes not support multi-byte characters and probably will not support multi-byte characters for the foreseeable future Jan 9, 2020 at 2:22
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.
-
-
3
-
plus 1 for answering the 'with sed' part of the question and then mentioning that
cutis better– s gSep 19, 2016 at 6:32
sed 's/^.\{,5\}//' file.dat
-
4BSD sed does not accept the at most bound (
{,5}) , this is GNU specific. An expression that works on both would besed 's/^.\{5\}//' file.dat– TristanFeb 26, 2015 at 12:15