我正在尝试导出我的Kunena论坛帖子,将它们导入我们新的wp论坛服务器。为此,我创建了2个文件...一个包含以下格式的消息:
(`id`, `parent`, `thread`, `catid`, `name`, `userid`, `email`, `subject`, `time`, `ip`, `topic_emoticon`, `locked`, `hold`, `ordering`, `hits`, `moved`, `modified_by`, `modified_time`, `modified_reason`)
另一个包含消息的文本:
(`mesid`, `message`)
从第一个文件中我只需要“fields”id,parent,time,userid,subject和hits。 从第二个我需要相应的“字段”消息
之后它的格式应该是这样的:
(`id`, `message`, `parent`, `time`, `userid`, `subject`, `hits`)
由于有数百个帖子和副本&粘贴的东西真的很耗时我认为通过脚本执行此操作要容易得多...最好是通过PowerShell ...
希望你们能帮助我......
$outputFile = "C:\logFile.txt"
$path = "C:\kunena_messages.txt"
$path2 = "C:\kunena_messages_text.txt"
get-content $path | % {$array = $_ -split ",","0"
$message = get-content $path2 | %{If($_ -match ($array[0].Trim() -replace "\(","" )){
$msgArray = $_ -split ",","0"
$msgArray[1] -replace "\)",""}}
$newString = $array[0].Trim()+","+$message +","+$array[1].Trim()+","+`
$array[8].Trim()+","+$array[5].Trim()+","+$array[7].Trim()+","+`
$array[14].Trim()+")"
$newString | ac $outputFile
}
答案 0 :(得分:0)
您可以尝试这样的方法来获取所需的信息:
$outputFile = "C:\logFile.txt"
$path = "C:\test\test.txt"
get-content $path | %{$array = $_ -split ",","0"
$message ="This is a message"
$newString = "("+$array[0].Trim()+","+$message +","+$array[1].Trim()+","+`
$array[8].Trim()+","+$array[5].Trim()+","+$array[7].Trim()+","+`
$array[14].Trim()+")"
$newString | ac $outputFile
}
这将在给定文件($outputFile
)中提供以下输出。
("`id`,`This is a message`,`parent`,`time`,`userid`,`subject`,`hits`)
("`id2`,`This is a message`,`parent2`,`time`,`userid`,`subject`,`hits`)
("`id3`,`This is a message`,`parent2`,`time`,`userid`,`subject`,`hits`)
正如你所看到的,我已经从信息中挑选出你需要的所有部分;因为我不确定你是如何将这两者联系起来的。您需要做的就是使用类似的方法来获取正确的消息并将其放入变量$message
。
假设您的ID和MesID相同,您可以对$message
变量使用类似的内容:
$path2 = "C:\Messages\test.txt"
$message = get-content $path2 | %{ $msgArray = $_ -split ",","0" -replace "\)",""
$msgArray = $msgArray -replace "\(",""
$m = $array[0].Trim() -replace "`"",""
If($msgArray[0].Trim() -eq $m){$msgArray[1]}
}
$path2
是您的消息文件的路径。
所以它们应该是这样的:
$outputFile = "C:\logFile.txt"
$path = "C:\kunena_messages.txt"
$path2 = "C:\kunena_messages_text.txt"
get-content $path | %{$array = $_ -split ",","0"
$array = $array -replace "\(","" `
-replace "\)","" `
-replace "`"",""
$message = get-content $path2 | %{ $msgArray = $_ -split ",","0" -replace "\)",""
$msgArray = $msgArray -replace "\(",""
$m = $array[0].Trim() -replace "`"",""
If($msgArray[0].Trim() -eq $m){$msgArray[1]}
}
$newString = "("+$array[0].Trim()+","+$message +","+$array[1].Trim()+","+`
$array[8].Trim()+","+$array[5].Trim()+","+$array[7].Trim()+","+`
$array[14].Trim()+")"
$newString | ac $outputFile
}