批处理文件 - 将大量文本复制到.txt文件中

时间:2012-09-05 22:51:16

标签: file batch-file lines copying

我想要它,所以当我点击批处理文件时,它会将大量内容复制到批处理文件中,我尝试使用>>方法,(回声示例>> example.txt),它只复制我想要复制的一半,我有很多行,所以我想知道是否有最多的行要复制,如果没有为什么它不是要复制我想要复制的所有东西吗? (我希望它复制大约150行) 编辑:这是我想要做的:

SET FILECONTENTS=1.) In the url of the item you want to use the buy button on, Put Javascript:startbuy();^  
 2.) Inspect element on buy button.^  
 3.) Put the code at the bottom in it.^  
 4.) You now no longer need to refresh once the item goes onsale.^  
 <input type="submit" class="newPurchaseButton" value=""^  
ECHO %FILECONTENTS%>>testingfile.txt

到目前为止,它不起作用。

2 个答案:

答案 0 :(得分:1)

大多数人通过在脚本中使用一百个echo语句(每行一个)来以错误的方式执行此操作,但有更好的方法。最好的方法是:

@echo off
setlocal EnableDelayedExpansion
set "LA=^<"
set "RA=^>"
:: 2 blank lines required below set NLM !
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%

SET FILECONTENTS=^
 1.) In the url of use the buy button on, Put Javascript:startbuy();!NL!^
 2.) Inspect element on buy button.!NL!^
 3.) Exclamation^^! Put the code at the bottom in it.!NL!^
 4.) You now no longer need to refresh once the item goes onsale.!NL!^
 !LA!input type=^"submit^" class=^"newPurchaseButton^" value=^"^"!RA!

ECHO %FILECONTENTS%
ECHO %FILECONTENTS%>>test.txt     
pause

答案 1 :(得分:1)

您尝试使用<>字符时代码失败,但这些是批处理的特殊字符(它们保留用于重定向)。

但是你可以逃避它们,另外你应该使用延迟扩展的echo命令来避免同样的问题。

setlocal EnableDelayedExpansion
SET FILECONTENTS=^
 1.) In the url of the item you want to use the buy button on, Put Javascript:startbuy();^
 2.) Inspect element on buy button.^
 3.) Put the code at the bottom in it.^
 4.) You now no longer need to refresh once the item goes onsale.^
 ^<input type="submit" class="newPurchaseButton" value=""^>

>>testingfile.txt ECHO !FILECONTENTS!

编辑:替代方式

如果您还想创建换行符,可以在块中使用简单的echo语句

(
  echo 1.^) In the url of the item you want to use the buy button on, Put Javascript:startbuy(^);
  echo 2.^) Inspect element on buy button.
  echo 3.^) Put the code at the bottom in it.
  echo 4.^) You now no longer need to refresh once the item goes onsale.
  echo ^<input type="submit" class="newPurchaseButton" value=""^>
) > testingfile.txt

有关更多解决方案,请阅读SO:Splitting Doublequoted Line Into Multiple Lines in Windows Batch