2013-03-20 80 views
0

我有很多文本文件;如何批量搜索和替換值爲文本文件中的值* 2

Value 800 
Amount 50 

Value 600 
Amount 40 

我想所有的數字翻一番

Value 1600 
Amount 100 

Value 1200 
Amount 80 

是否有一些可以搜索 「價值」 非常基本的程序&「金額「後讀取整數,並用相同的值替換* 2

或某種方式使用記事本++,autoIt或其他一些簡單的程序/工具做到這一點?

+0

在它是什麼語言??? – BBdev 2013-03-28 03:18:37

回答

0

你至少應該有一個先走了,然後問的問題;)

請備份你的文件,然後再嘗試這個AutoIt腳本:

#include <File.au3> 

$textFiles = _FileListToArray(@ScriptDir, "*.txt", 1) 

for $fileIndex = 1 to $textFiles[0] 
$textFile = $textFiles[$fileIndex] 

    ConsoleWrite($textFile & @CRLF) 

    Local $lines 
    _FileReadToArray($textFile, $lines) 

    $output = FileOpen($textFile, 2) 

    For $i = 1 To $lines[0] 
     $line = $lines[$i] 
     $tokens = StringSplit($line, " ") 

     If $tokens[0] = 2 Then 
      $newLine = $tokens[1] & " " & $tokens[2] * 2 
      FileWrite($output, $newLine & @CRLF) 
     EndIf 
    Next 

    FileClose($output) 
Next