Page 1 of 1

Add an IP address to the start of every line in a text file

Posted: 31 May 2015 15:31
by code
I take the occasion to greet you and thank you for your help ..forgive my English but I write from Italy
I have a list of servers in a .txt file must modify it by adding thiss 127.0.0.1 before each server, including a space between 127.0.0.1 and the server name
I would need to enter in a text file that contains a list of servers written vertically, I have to create a file that allows me to enter 127.0.0.1 in front of each server but 'keeping a space between 127.0.0.1 and the server name, example:

171.24.24.48
172.89.89.24

must 'become so in the file text

127.0.0.1 171.24.24.48
127.0.0.1 172.89.89.24

Re: please i need your aid

Posted: 01 Jun 2015 00:06
by code
good morning this a worked

Code: Select all

@ECHO OFF
SET "NomeFile_sorgente=file1.txt"
SET "NomeFile_Destinazione=C:\Users\percorso\Documents\file2.txt"

ECHO. > %NomeFile_Destinazione%
FOR /F "delims=" %%a IN (%NomeFile_sorgente%) DO ECHO 127.0.0.1 %%a >>  %NomeFile_Destinazione%
 PAUSE


essentially.. takes the contents of the file2 and writes it in the file1 and adding 127.0.0.1 before each line; I found online and I changed something for me, I unfortunately do not know the programming, however, is very rewarding

Re: please i need your aid

Posted: 01 Jun 2015 04:52
by miskox

Code: Select all

@echo off
if exist output.txt del output.txt
for /f %%f in (input.txt) do >>output.txt (echo 127.0.0.1 %%f)


HTH.

Saso

Re: please i need your aid

Posted: 01 Jun 2015 12:08
by code
miskox Thank you very much , I love this language, if you have a good free book for beginners, you can send me the link ? thanks, I would like to learn