Looking for an elegant way, when at the end of a bash script to cleanup the resulting file if:
- the first character of the line below the line to be deleted is
#or #is the first character of the last line in the file.
File could look like this (line numbers of reference are in [] but are not in the file itself):
[1] # foo
[2] bar1
[3] bar2
[4] bar3
[5] # foob
[6] #ar
[7] ar1
[8] ar2
[9] ar3
[10] #
In the above example I'd like to delete lines 5 and 10. I do not want any line starting with # to be followed by a line starting with # and I do not want the last line of the file to start with #.
EDIT: Expected output:
[1] # foo
[2] bar1
[3] bar2
[4] bar3
[5] #ar
[6] ar1
[7] ar2
[8] ar3
Teaching myself bash as I go and am super confused by sed and awk syntax, but I suspect they are the answer here.
[4]deleted? the first character of the line below it is also#