the structure you described is not exactly what i meant to suggest here s more detail status edits s a z more sed commands here if  csv then status edits status edits s fi sed status edits file that s still not complete  i think there ll need to be some other  changes to account for other differences  you may find it s  convenient to write content to a temporary file  take a look at  the  mktemp  command 