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/192.168.1.12 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/192.168.1.12 vm/’ /etc/hosts

Leave a comment

Category: Linux,Mac

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.