使用BAT脚本更改txt文件内容


0

我需要获取文本文件内容并将它们排序到一列并重新保存文件。

该文件的内容如下所示,所有内容都在一个字符串中....

core.jar:core-junit.jar:bouncycastle.jar:ext.jar:framework.jar:framework2.jar:telephony-common.jar:mms-common.jar:android.policy.jar:services.jar:apache-xml.jar:sec_edm.jar:seccamera.jar:scrollpause.jar:stayrotation.jar:smartfaceservice.jar:abt-persistence.jar:secocsp.jar:sc.jar 

我需要在一栏中让它们看起来像这样......

core.jar:
core-junit.jar:
bouncycastle.jar:
ext.jar:
......etc

而且为了让事情变得更加困难,我不会总是知道文字上的名字是什么。我知道虽然会有一个冒号分隔名字。那么也许有一种方法可以在冒号之间拉文本并保存到单个列中的新文本中?

编辑**或者,我认为,从行到列更改的脚本将起作用。

谢谢你提供的所有帮助。


Windows批处理,我们假设?我很快就会做点什么。
Wally 2013年

Answers:


0

使用此代码。输入foo.txt和输出是foobar.txt。我不明白递归如何在%% b变量上运行,但它在Windows 7 Pro常规命令shell上运行。

@echo off
setlocal enabledelayedexpansion
goto afterfunctions

REM http://stackoverflow.com/questions/5837418/how-do-you-get-the-string-length-in-a-batch-file
:trimstring <therestVar> <inputVar>
(
    setlocal EnableDelayedExpansion
    for /f "tokens=1,* delims=:" %%a in ("!%~2!") do (
        echo %%a
        REM echo %%b
        REM %%b is the rest of it. Now we need to call this function with just that string.
        call :trimstring result %%b
    )
)
(
    endlocal
    exit /b
)

:afterfunctions
for /f "delims=" %%x in (foo.txt) do set mystring=%%x
set thisstring=%mystring%
call :trimstring result mystring > foobar.txt
:eof
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.