[Solved] Add single line at the end of multiple files in IntelliJ


Just use Replace in Files (Edit → Find → Replace in Files, or Ctrl+Shift+R in Windows and Linux / ⌘+Shift+R in Mac) to replace this regex:

(.)\Z

with this:

$1\nThis is your line

in any files you need. That’s all.


Explanation:

The regex (.)\Z matches and captures the last character in the whole file:

  • (.) matches and captures any character
  • \Z matches EOF (end-of-file)

And the replacement uses it to add your line after it:

  • $1 uses the first capture group (i.e. the previously matched character, to avoid removing it)
  • \n introduces a new line
  • This is your line is the line you want to add

You may use the File mask option to select the files you want to change:

enter image description here

Result:

enter image description here

0

solved Add single line at the end of multiple files in IntelliJ