在程序中我得到一个输入说名字....如何从打印了评论的文件打印值?
从文件通过我行读值线: 说,文件中包含...
hello
hai
如果我想打印像
hello name in batch file
hai name in batch file
如何做到这一点?
在程序中我得到一个输入说名字....如何从打印了评论的文件打印值?
从文件通过我行读值线: 说,文件中包含...
hello
hai
如果我想打印像
hello name in batch file
hai name in batch file
如何做到这一点?
以下(纯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> _
对于Windows命令行使用
ECHO %1
为%%一个在wish.txt请键入%%一个只打印你好 海 如何将类型和呼应一个for循环? – anitha 2010-01-25 06:08:40
怎么样一个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" ;
}
我用echo作为名字 echo %% a%name%在批处理文件中 但不起作用.... – anitha 2010-01-25 06:46:39
您需要确保名称已被定义,如'set name = Bob'声明。 – paxdiablo 2010-01-25 06:48:40