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

LinuxUnixSed

Linux Problem Overview


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?

Linux Solutions


Solution 1 - Linux

Use cut:

cut -c6-

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

Solution 2 - Linux

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.

Solution 3 - Linux

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

Solution 4 - Linux

awk '{print substr($0,6)}' file

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJBegView Question on Stackoverflow
Solution 1 - LinuxGreg HewgillView Answer on Stackoverflow
Solution 2 - LinuxPhilRView Answer on Stackoverflow
Solution 3 - LinuxIgnacio Vazquez-AbramsView Answer on Stackoverflow
Solution 4 - Linuxghostdog74View Answer on Stackoverflow