简体   繁体   English

批处理文件-阅读txt文件并重新格式化文本

[英]Batch File - Read txt file and reformat the text

I have a pretty horrible looking txt file, and am looking for a way to reformat the content of the file. 我有一个看起来非常恐怖的txt文件,并且正在寻找一种重新格式化文件内容的方法。 An example of the file is shown below 该文件的示例如下所示

{'4': 20947, 's': 3263, '6': 20837, 'A': 3490, 'U': 3467, 'g': 3277, 'd': 3245, 'H': 3534, 'Y': 3534, 'm': 3297, 'r': 3400, 'u': 3157, 'X': 3501, 'i': 3354, '2': 21012, 'V': 3398, '3': 20864, 'G': 3528, 'M': 3540, '\n': 30212, 'n': 3296, 'T': 3620, 'R': 3500, 'j': 3205, 'W': 3512, 'N': 3483, 'v': 3260, 'I': 3488, 'e': 3179, 'w': 3290, 'P': 3575, '0': 9455, 'L': 3473, 'q': 3284, '1': 21093, 'b': 3216, '9': 18626, 'F': 3494, '8': 20916, '7': 20746, 'x': 3231, 'o': 3162, 'y': 3295, '5': 21467, 'p': 3245, 'E': 3535, 'Q': 3345, 'K': 3619, 'h': 3320, 'f': 3295, 'l': 3284, 'D': 3590, 'c': 3258, 'C': 3473, 'k': 3213, 'a': 3023, 'J': 3504, 't': 3246, 'O': 3463, 'S': 3522, 'B': 3514}

I want to be able to read the character in quotes '' and then print the value that follows after the colon, in alphanumerical order. 我希望能够读取引号''中的字符,然后按字母数字顺序打印冒号后面的值。 For example: 例如:

a: 1233
A: 2345
b: 1023
B: 1542
c: 2415
# And so on....

For ease, I thought doing this via a batch file would be ideal, however do not know how to go about doing this - any help would be great! 为简便起见,我认为通过批处理文件进行此操作是理想的选择,但是不知道如何执行此操作-任何帮助都将非常有用!

remove all charcters that you don't need, then parse with a plain for . 删除您不需要所有charcters,然后用普通的分析for Sort the output, done. 排序输出,完成。

@echo off
<input.txt set /p line=
set line=%line:{=%
set line=%line:}=%
set line=%line:'=%
set line=%line: =%
((for %%i in (%line%) do @echo %%i)|sort)>output.txt

If you need for the space to appear after the colon, then you might try: 如果需要在冒号后面显示空格,则可以尝试:

@echo off
setlocal enabledelayedexpansion

<crackline.txt set /p line=

set line=%line:{=%
set line=%line:}=%
set line=%line:'=%
set line=%line: =%

for %%i in (%line%) do (
    set L=%%i
    @echo !L::=: !
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM