-1

I have a bunch of around 600 files i need to add a line to the top of them, pushing all other lines one row down.

How i can do this most easily? The files are .java files.

Thanks in advance!

Martijn Deleij
  • 91
  • 1
  • 16
  • This was the first result on Google for "java prepend file": http://stackoverflow.com/questions/2537944/prepend-lines-to-file-in-java. Please delete this question. – musical_coder Dec 26 '13 at 01:09
  • 1
    No, i am looking for a way that involves notepad++ or anything, i cannot program java, not looking for a way to do it in java – Martijn Deleij Dec 26 '13 at 01:20
  • yeah that's clear but so why the hell mention anything about .java at all. it is completely irrelevant what extension the file is or what's in it. except maybe if it's unicode or ascii 'cos unicode have a funny code at the beginning. i don't know if java files are ever unicode. but a good solution could work for ascii or unicode – barlop Dec 26 '13 at 01:35
  • not notepad++ but sed "1i\first line" -i.bak a.a so perhaps some cmd.exe shell for loop to do this on all files. so with for %a in (*.*) do `@`echo %a So, for %a in (*.*) do `@`echo sed "1i\first line" -i.bak %a <-- removing the `@`echo. – barlop Dec 26 '13 at 02:50
  • See the answer in http://stackoverflow.com/questions/17234123/search-and-replace-only-first-result-on-each-file-with-notepad/17234639#17234639 – AdrianHHH Dec 26 '13 at 08:42

1 Answers1

1

In Notepad++, go to Search > Find in Files... menu (shortcut CTRL+Shift+F) and do the following:

  1. Find what:

    (.+)
    
  2. Replace with:

    Your new line\n$1
    
  3. Filters:

    *.java
    
  4. Directory: choose the directory with these 600 files

  5. Select radio button "Regular Expression" and check ". matches newline"

  6. Then press "Replace in Files"

enter image description here

psxls
  • 6,807
  • 6
  • 30
  • 50