2010-01-25 71 views

回答

0

以下(纯cmd)脚本将做到这一点:

@echo off 
setlocal enableextensions enabledelayedexpansion 
for /f %%a in (infile.txt) do (
    echo %%a name in batch file 
) 
endlocal 

对于输入文件(infile.txt):

 
    hello 
    hai 

它产生:

 
hello name in batch file 
hai name in batch file 

我收集你需要调整“在批处理文件名”的脚本位被什么东西更适合(如"Bob"为例)。


更新:

只要你有正确地创建了name变量进入for循环,你也可以使用名称变量之前。例如,下面的脚本:

@echo off 
setlocal enableextensions enabledelayedexpansion 
set /p name=Enter name: 
for /f %%a in (infile.txt) do (
    echo %%a !name! 
) 
endlocal 

允许:

c:\pax> .\go.cmd 
Enter name: Pax 
hello Pax 
hai Pax

c:\pax> _
+0

我用echo作为名字 echo %% a%name%在批处理文件中 但不起作用.... – anitha 2010-01-25 06:46:39

+0

您需要确保名称已被定义,如'set name = Bob'声明。 – paxdiablo 2010-01-25 06:48:40

0

对于Windows命令行使用

ECHO %1 
+0

为%%一个在wish.txt请键入%%一个只打印你好 海 如何将类型和呼应一个for循环? – anitha 2010-01-25 06:08:40

0

怎么样一个Perl的解决方案:

#!/usr/bin/perl -w 

my $file = "file.txt"; 
open(INFO,"<$file") or die "can't open file" ; 

while(<INFO>) 
{ 
    chomp $_; 
    print "$_ name in batch file\n" ; 
}