0

I have an active test.txt file with information in it. Using the batch, I would like to add a website address at bottom right after the last line.

Example - test.txt file -

Paragraph 1

Paragraph 2

Paragraph 3

Paragraph x Here is where I want to insert the web URL (no extra blank line after the last paragraph)

Please guide me.

Thanks Kyle

Kyle
  • 1
  • 1
    try with: TYPE firstfile.txt >> newfile.txt – Kenan Zahirovic Sep 23 '14 at 22:33
  • @KenanZahirovic - That can't work. First off, you never add the URL, and second, even if you did, it would appear on a new line if the last line in the file already has a newline. The OP wants the URL appended to the end of the last non-empty line. – dbenham Sep 24 '14 at 01:05

1 Answers1

0

There is a simple and efficient solution using REPL.BAT - a hybrid JScrpipt/batch utility that performs a regular expression find/replace operation on stdin, and writes the result to stdout. REPL.BAT is pure script that runs natively on any modern Windows machine from XP onward.

The commands below effectively append text to the end of the last non-empty line found in the text file.

type "test.txt"|repl "([^\r\n]+)$(?![\r\n]*[^\r\n])" "$1 your URL" m >"test.txt.new"
move /y "test.txt.new" "test.txt" >nul
Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390