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?
To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.
Removing the first n characters To remove the first n characters of a string, we can use the parameter expansion syntax ${str: position} in the Bash shell.
There is no available to delete all contents of the file. How to delete all contents of the file using sed command.
Use cut
:
cut -c6-
This prints each line of the input starting at column 6 (the first column is 1).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With