Using the terminal (in OSX), how do I modify a specific line of a file?
e.g. I have a javascript file and want to comment out line 300 by prepending //
Using the terminal (in OSX), how do I modify a specific line of a file?
e.g. I have a javascript file and want to comment out line 300 by prepending //
The easiest way is to use sed
:
sed -i '300s%^%//%' myfilename.js
Some versions of sed
(such as the BSD version that ships with Mac OS X), require an explicit argument for -i
. If you don't want a backup, use the empty string.
sed -i "" '300s%^%//%' myfilename.js