批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

[文本处理] 批处理该怎么筛选并复制出这些内容到另外个文件?

本帖最后由 elf_zhou 于 2022-6-20 13:35 编辑

附件中的txt需要把msgstr ""的都摘取出来复制到另外个txt中,但需要整段复制。
  1. # Game Japanese (Japan) translation.
  2. # Copyright Epic Games, Inc. All Rights Reserved.
  3. #
  4. msgid ""
  5. msgstr ""
  6. "Project-Id-Version: Game\n"
  7. "POT-Creation-Date: 2022-06-20 03:05\n"
  8. "PO-Revision-Date: 2022-06-20 03:05\n"
  9. "Language-Team: \n"
  10. "Language: ja-JP\n"
  11. "MIME-Version: 1.0\n"
  12. "Content-Type: text/plain; charset=UTF-8\n"
  13. "Content-Transfer-Encoding: 8bit\n"
  14. "Plural-Forms: nplurals=1; plural=0;\n"
  15. #. Key: 2295A5CE4C86A968A4F8909861C06D94
  16. #. SourceLocation: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.ThirdPersonExampleMap:PersistentLevel.TextRenderActor_1.NewTextRenderComponent.Text
  17. #: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.ThirdPersonExampleMap:PersistentLevel.TextRenderActor_1.NewTextRenderComponent.Text
  18. msgctxt ",2295A5CE4C86A968A4F8909861C06D94"
  19. msgid "Third Person"
  20. msgstr "测试"
  21. #. Key: 2C5373B4420A4B4B029E54B3650775C3
  22. #. SourceLocation: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本3
  23. #: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本3
  24. msgctxt ",2C5373B4420A4B4B029E54B3650775C3"
  25. msgid "新增的文本"
  26. msgstr ""
  27. #. Key: C01A2B544C59EDD5D36CDCB9CB52C463
  28. #. SourceLocation: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本2
  29. #: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本2
  30. msgctxt ",C01A2B544C59EDD5D36CDCB9CB52C463"
  31. msgid "修改的文本"
  32. msgstr "修改的文本"
  33. #. Key: laodewenben
  34. #. SourceLocation: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本1
  35. #: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本1
  36. msgctxt ",laodewenben"
  37. msgid "老的文本"
  38. msgstr ""
复制代码
筛选出来的复制到另外个txt的结果应该是
  1. #. Key: 2C5373B4420A4B4B029E54B3650775C3
  2. #. SourceLocation: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本3
  3. #: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本3
  4. msgctxt ",2C5373B4420A4B4B029E54B3650775C3"
  5. msgid "新增的文本"
  6. msgstr ""
  7. #. Key: laodewenben
  8. #. SourceLocation: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本1
  9. #: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本1
  10. msgctxt ",laodewenben"
  11. msgid "老的文本"
  12. msgstr ""
复制代码

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "delims=" %%i in ('dir /b /a-d *.txt') do (
  4.     set n=0
  5.     for /f "usebackq delims=" %%j in ("%%i") do (
  6.         set "str=%%j"
  7.         if "!str:~,7!"=="#. Key:" set n=1
  8.         if !n! equ 1 echo,%%j
  9.         if "%%j"=="msgstr """ echo,&set n=0
  10.     )
  11. )
  12. pause
复制代码

TOP

qixiaobin0715 发表于 2022-6-20 12:30



    大佬出来结果是这样的,好像没有筛选出来。。。
#. Key: 2295A5CE4C86A968A4F8909861C06D94
#. SourceLocation:      /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.ThirdPersonExampleMapersistentLevel.TextRenderActor_1.NewTextRenderComponent.Text
#: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.ThirdPersonExampleMap:PersistentLevel.TextRenderActor_1.NewTextRenderComponent.Text
msgctxt ",2295A5CE4C86A968A4F8909861C06D94"
msgid "Third Person"
msgstr "娴嬭瘯"
#. Key: 2C5373B4420A4B4B029E54B3650775C3
#. SourceLocation:      /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.鏂囨湰3
#: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.鏂囨湰3
msgctxt ",2C5373B4420A4B4B029E54B3650775C3"
msgid "鏂板鐨勬枃鏈?
msgstr ""

#. Key: C01A2B544C59EDD5D36CDCB9CB52C463
#. SourceLocation:      /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.鏂囨湰2
#: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.鏂囨湰2
msgctxt ",C01A2B544C59EDD5D36CDCB9CB52C463"
msgid "淇敼鐨勬枃鏈?
msgstr ""

#. Key: laodewenben
#. SourceLocation:      /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.鏂囨湰1
#: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.鏂囨湰1
msgctxt ",laodewenben"
msgid "鑰佺殑鏂囨湰"
msgstr ""

TOP

本帖最后由 qixiaobin0715 于 2022-6-20 17:08 编辑

回复 3# elf_zhou
如果附件中的txt文件只有一个,假设为1.txt,将下面代码另存为ANSI编码:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set hh=^
  4. (for /f "delims=" %%i in (1.txt) do (
  5.     set "str1=%%i"
  6.     if "!str1:~,7!"=="#. Key:" set n=1
  7.     if !n! equ 1 set str=!str!!hh!%%i
  8.     if "!str1:~,6!"=="msgstr" (
  9.         set n=0
  10.         if "%%i"=="msgstr """ echo,!str!
  11.         set str=
  12.     )
  13. ))>new_1.txt
  14. pause
复制代码
上面第4、5行空行要保留,不要去除。
1

评分人数

TOP

回复  elf_zhou
如果附件中的txt文件只有一个,假设为1.txt,将下面代码另存为ANSI编码:上面第4、5行空行 ...
qixiaobin0715 发表于 2022-6-20 15:44

厉害,多谢大佬搞定拉

TOP

回复  elf_zhou
如果附件中的txt文件只有一个,假设为1.txt,将下面代码另存为ANSI编码:上面第4、5行空行 ...
qixiaobin0715 发表于 2022-6-20 15:44

顺便再问下大佬怎么将结果全部保存到一个新的txt中,我自己加了一段只保存了第一个筛选出的结果

TOP

回复 6# elf_zhou
已修改
1

评分人数

TOP

返回列表