sed: 1: “/etc/hosts”: extra characters at the end of h command

Writing by on Wednesday, 11 of March , 2015 at 4:11 am

I was trying a simple sed -i on my Mac and was running into

# Does NOT work on Mac
$ sed -i ‘s/^192.168.*vm/ vm/’ /etc/hosts
sed: 1: “/etc/hosts”: extra characters at the end of h command

A quick google search resulted in stackoverflow getting sed error which has the solution. Apparently, Mac uses BSD sed and Linux uses GNU sed which have different set of arguments. So provide the extra argument in Mac as shown below.

# Adding the extra argument will work on your Mac
$ sed -i ” ‘s/^192.168.*vm/ vm/’ /etc/hosts

Leave a comment

Category: Linux,Mac

No Comments

No comments yet.

Leave a comment

You must be logged in to post a comment.

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.