You can read an entire file into an array with file() function. Each line becomes an element of an array which the function returns. See http://www.php.net/manual/function.file.php for details.
Then simply manipulate the array as you wish. You'll find array functions quite useful, and also regular expressions can come in handy. In the end, write the array into a file, overwriting the previous one.
If your app needs a web interface, go ahead and use PHP. Shell scripts can be very dangerous when accessible from the net. If it's not to be used from the net, I'd use a shell script or a Perl script.
-jani