What's the easiest way for me to script moving the last line of a text file to the Nth line? I have a whole directory full of files that need the exact same treatment.

Update: My solution in replies!

#AskFedi #AskFediverse #LazyWeb

Turns out vim can do this directly in terminal:

vim +'$-0,$m0’ +'wq' FILE

Will move the last line ($-0) to the first line ($m0) and write the result (+wq).

Throw this in a loop and it did exactly what I needed:

for FILE in *.html; do vim +'$-0,$m7' +'wq' $FILE; done

^ loops through all html files in current directory, moves the last line to the 7th line.

Did I just move an HTML image to front matter on 120 blog posts at once?

Yes. Yes I did.