You can use guestfish, a command-line wrapper for libguestfs:
libguestfs is a set of tools for accessing and modifying virtual machine (VM) disk images. You can use this for viewing and editing files inside guests, scripting changes to VMs, monitoring disk used/free statistics, creating guests, P2V, V2V, performing backups, cloning VMs, building VMs, formatting disks, resizing disks, and much more
All this functionality is available through a scriptable shell called guestfish, or an interactive rescue shell virt-rescue.
Get a shell to interact with the disk image (use -r to make the volumes read-only, -w if you want to be able to edit files on the image):
$ sudo guestfish -r -a DiskImage.img
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.
Type: ‘help’ for help on commands
‘man’ to read the manual
‘quit’ to quit the shell
><fs> run
><fs> list_filesystems
/dev/sda1: vfat
/dev/sda2: ext4
First volume is my boot volume, second is my root. To interact with the files on either of them, mount them first:
><fs> mount /dev/sda2 /
><fs> ls /
bin
boot
dev
etc
home
...
To edit a file directly:
><fs> edit /home/pi/.bashrc
You can do lots of other things as well, like copy files to/from the image from/to your local machine or change the partitions. You can also script all these commands together from your local shell as such:
sudo guestfish add DiskImage.img : run : list_filesystems : mount /dev/sda2 / : ls / : edit /home/pi/.bashrc
And when you are done, the disk image itself will have changed. Burn your new image to a new SD card and voilà!