I have a gazillion files which need to be reduced in size. I found that most (not all) files have an end section which can be cut without losing information:
Data 1
Data 2
something_unimportant_here END DATA
Rubbish 1
Rubbish 2
How can I edit a file (end hence, all) by deleting the line including "END DATA" and all following, in-place, changing only those the files that contain the pattern, thereby minimising write access to the disk (many, many files and slow disk).
If possible, I would like to add a new last line to the file (my own end tag) so that the file's syntax stays correct -- again, only in those files containing the pattern.
I was thinking of using ed
, like
echo ',s/END DATA/ ???? '\\n'q'\\n'wq' | ed "$file"
but cannot seem to manage the ???? part correcty.
Expected output:
Data 1
Data 2
NEW END