How to remove the first and last two characters from a text file using sed?

I have a text file like this

abcdefg
abcdefg
abcdefg
abcdefg

How to remove the first and last two characters from each line using sed? I would like to get the result as follows

bcde
bcde
bcde
bcde
+3
source share
2 answers
sed  's/^.\(.*\)..$/\1/'  file

+4
source

This might work for you:

sed 's/^.\|..$//g' file
0
source

All Articles