Prepend files in OS X using the Command Line
This is a neat little “trick” to prepend something simple to the beginning of a file. Linux is funny in the way that you can easily append to a file by using echo "append me to the file" >> FILE but theres no real simple way to prepend. Most snippets I’ve seen use a tmp file but thats silly when OS X gives you some amazing programs.
Using pbcopy and pbpaste can save your life sometimes and are probably one programs I miss the most when using Linux. Anyway, heres just a simple “1 liner” for prepending.
cat FILE | pbcopy && echo "Prepend Text" > FILE && pbpaste >> FILE
Pretty simple, but it can be useful at times — like when you have a script that would be better off with a shebang line than being run by hand and you’re too lazy to open an editor.







Add Yours
YOU