3 ms·
Since bash doesn't provide a prepend operator, I define a shell function for that purpose, making use of ed, without need for a temp/intermediate file: file
by michaelsbradley 10y ago
Since bash doesn't provide a prepend operator, I define a shell function for that purpose, making use of ed, without need for a temp/intermediate file:
file_prepend () {
local ed_cmd="1i"
if [ ! -f "$2" ]; then
touch "$2"
ed_cmd="a"
fi
printf '%s\n' H "$ed_cmd" "$1" . w | ed -s "$2"
}