标题: [文本处理] 批处理该怎么筛选并复制出这些内容到另外个文件? [打印本页]
作者: elf_zhou 时间: 2022-6-20 11:28 标题: 批处理该怎么筛选并复制出这些内容到另外个文件?
本帖最后由 elf_zhou 于 2022-6-20 13:35 编辑
附件中的txt需要把msgstr ""的都摘取出来复制到另外个txt中,但需要整段复制。- # Game Japanese (Japan) translation.
- # Copyright Epic Games, Inc. All Rights Reserved.
- #
- msgid ""
- msgstr ""
- "Project-Id-Version: Game\n"
- "POT-Creation-Date: 2022-06-20 03:05\n"
- "PO-Revision-Date: 2022-06-20 03:05\n"
- "Language-Team: \n"
- "Language: ja-JP\n"
- "MIME-Version: 1.0\n"
- "Content-Type: text/plain; charset=UTF-8\n"
- "Content-Transfer-Encoding: 8bit\n"
- "Plural-Forms: nplurals=1; plural=0;\n"
-
- #. Key: 2295A5CE4C86A968A4F8909861C06D94
- #. SourceLocation: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.ThirdPersonExampleMap:PersistentLevel.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 ""
复制代码
筛选出来的复制到另外个txt的结果应该是- #. Key: 2C5373B4420A4B4B029E54B3650775C3
- #. SourceLocation: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本3
- #: /Game/ThirdPersonBP/Maps/ThirdPersonExampleMap.Default__ThirdPersonExampleMap_C.文本3
- msgctxt ",2C5373B4420A4B4B029E54B3650775C3"
- 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 ""
复制代码
作者: qixiaobin0715 时间: 2022-6-20 12:30
- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in ('dir /b /a-d *.txt') do (
- set n=0
- for /f "usebackq delims=" %%j in ("%%i") do (
- set "str=%%j"
- if "!str:~,7!"=="#. Key:" set n=1
- if !n! equ 1 echo,%%j
- if "%%j"=="msgstr """ echo,&set n=0
- )
- )
- pause
复制代码
作者: elf_zhou 时间: 2022-6-20 13:30
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 ""
作者: qixiaobin0715 时间: 2022-6-20 15:44
本帖最后由 qixiaobin0715 于 2022-6-20 17:08 编辑
回复 3# elf_zhou
如果附件中的txt文件只有一个,假设为1.txt,将下面代码另存为ANSI编码:- @echo off
- setlocal enabledelayedexpansion
- set hh=^
-
-
- (for /f "delims=" %%i in (1.txt) do (
- set "str1=%%i"
- if "!str1:~,7!"=="#. Key:" set n=1
- if !n! equ 1 set str=!str!!hh!%%i
- if "!str1:~,6!"=="msgstr" (
- set n=0
- if "%%i"=="msgstr """ echo,!str!
- set str=
- )
- ))>new_1.txt
- pause
复制代码
上面第4、5行空行要保留,不要去除。
作者: elf_zhou 时间: 2022-6-20 16:27
回复 elf_zhou
如果附件中的txt文件只有一个,假设为1.txt,将下面代码另存为ANSI编码:上面第4、5行空行 ...
qixiaobin0715 发表于 2022-6-20 15:44
厉害,多谢大佬搞定拉
作者: elf_zhou 时间: 2022-6-20 17:06
回复 elf_zhou
如果附件中的txt文件只有一个,假设为1.txt,将下面代码另存为ANSI编码:上面第4、5行空行 ...
qixiaobin0715 发表于 2022-6-20 15:44
顺便再问下大佬怎么将结果全部保存到一个新的txt中,我自己加了一段只保存了第一个筛选出的结果
作者: qixiaobin0715 时间: 2022-6-20 17:08
回复 6# elf_zhou
已修改
作者: hfxiang 时间: 2022-7-12 09:15
回复 elf_zhou
如果附件中的txt文件只有一个,假设为1.txt,将下面代码另存为ANSI编码:上面第4、5行空行 ...
qixiaobin0715 发表于 2022-6-20 15:44
借鉴大神的代码,可以解决小段(8000字节之内)文字的摘录,感谢。
但当要摘录的文字总长度达8000字节左右就会出现不可控的现象,能否用批处理的方法(不用第三方工具)摘录2关键字之间长度超过8000字节的文字段?
作者: qixiaobin0715 时间: 2022-7-12 15:15
本帖最后由 qixiaobin0715 于 2022-7-12 15:17 编辑
回复 8# hfxiang
单行长度不超过8192应当可以通过set /p可以实现,不会像楼主要求的那么精确。未试过。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |