I'd like to write a bash script that essentially automates this process:

vi filename.pdf

(open "filename.pdf" using vi)

:4,7d

(in vi command mode, delete lines 4-7)

O

(in vi command mode, tap shift+O (captial oh) to create new line)

<<>>

(in vi insert mode, type two lesser-thans and two greater-thans)

ESC

(switch vi to command mode)

:wq

(in vi command mode, save file and quit vi)

echo "Complete."
share|improve this question
4  
sed -i '4,7c\<<>>' filename.pdf – Costas Nov 11 '16 at 18:53
    
@Theophrastus. Can you explain why this is "nutzo"? – user847 Nov 11 '16 at 19:08
    
@Costas. Thanks! Do you want to post as answer and I mark it as the solution? – user847 Nov 11 '16 at 19:08
    
Perhaps you can suggest a better solution. mat (Metadata Anonymisation Toolkit) was recently modified in Debian (debian.org/security/2016/dsa-3708). I need to be able to remove metadata. When opening recent PDFs I've worked with, the data I need deleted was in lines 4-7 always. this sed thing seems to work. Hopefully MAT will get patched eventually. But until then I need solution. Comments? – user847 Nov 11 '16 at 19:16
1  
see my answer at askubuntu.com/questions/848275/… – Archemar Nov 11 '16 at 19:23
printf '%s\n' '4,7d' a '<<>>' . x | ex filename.txt && echo complete

You can't edit PDF files with a text editor, though.

share|improve this answer

This should automate your process.

vim -b -c '4s/.*/<<>>/' -c '5,7d' -c wq filename.pdf

Flag Breakdown

  • -b binary mode
  • -c {command} runs the vim automatically when the file is opened.

So -c '4s/.*/<<>>/' -c '5,7d' -c wq runs the vim command 4s/.*/<<>>/ followed by 5,7d followed by a wq.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.