Joel
Joel

Reputation: 67

How to delete 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 delete the first and last two characters from each line with sed? I would like to get the output like this

bcde
bcde
bcde
bcde

Upvotes: 3

Views: 1449

Answers (2)

potong
potong

Reputation: 58400

This might work for you:

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

Upvotes: 0

codaddict
codaddict

Reputation: 455020

sed  's/^.\(.*\)..$/\1/'  file

Upvotes: 4

Related Questions