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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
code
Posts: 6
Joined: 30 May 2015 15:52

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

#1 Post by code » 31 May 2015 15:31

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

code
Posts: 6
Joined: 30 May 2015 15:52

Re: please i need your aid

#2 Post by code » 01 Jun 2015 00:06

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

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: please i need your aid

#3 Post by miskox » 01 Jun 2015 04:52

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

code
Posts: 6
Joined: 30 May 2015 15:52

Re: please i need your aid

#4 Post by code » 01 Jun 2015 12:08

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

Post Reply