标题: [文本处理] 批处理BAT如何把多行的文本插入到另一个文本的指定位置? [打印本页]
作者: 767056325 时间: 2014-5-20 15:40 标题: 批处理BAT如何把多行的文本插入到另一个文本的指定位置?
把一个有多行的文本的内容全部插入到另一个文本的指定位置。
作者: Batcher 时间: 2014-5-20 18:53
请详细描述一下什么样的指定位置
作者: 767056325 时间: 2014-5-20 18:59
回复 2# Batcher
就是某一个文本的中间的一行。我是这样写的:
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('findstr /n .* importent.txt') do (
set "var=%%i"
set var=!var:*:=!
set /a j+=1
if !j! EQU 1 (set "Mstr=!var!") else (set "Mstr=!Mstr!&echo.!var!")
)
pause>nul
rem 定义变量延迟环境,关闭回显
cd /d D:\apktool123\smali\com\example\hellowrld
for /f "eol=* tokens=*" %%k in (MainActivity.smali) do (
rem 设置变量a为每行内容
set a=%%k
set "a=!a:invoke-virtual {p0, v0}, Lcom/example/hellowrld/MainActivity;->setContentView(I)V=%Mstr% !"
rem 把修改后的全部行存入$
echo !a!>>$)
rem 用$的内容替换原来a.txt内容
move $ MainActivity.smali
pause
就是将MainActivity.smali里面的一行内容“invoke-virtual {p0, v0}, Lcom/example/hellowrld/MainActivity;->setContentView(I)V”替换成importent.txt里面的内容。我是把文本读入Mstr。再将要替换的替换成Mstr里面的内容。但是出现了问题,运行完之后,修改的那一部分的换行,都没换行,而是变成了“echo.”。请问怎么解决。谢谢大神。
作者: Batcher 时间: 2014-5-20 21:49
回复 3# 767056325
把以下三个文本内容发出来看看:
importent.txt
MainActivity.smali
修改之后的希望得到的MainActivity.smali
作者: 767056325 时间: 2014-5-20 22:22
回复 4# Batcher
importent内容
invoke-virtual {p0}, Lcom/example/hellowrld/MainActivity;->getApplicationInfo()Landroid/content/pm/ApplicationInfo;
move-result-object v0
iget v1, v0, Landroid/content/pm/ApplicationInfo;->flags:I
and-int/lit8 v1, v1, 0x2
iput v1, v0, Landroid/content/pm/ApplicationInfo;->flags:I
if-eqz v1, :cond_0
invoke-static {}, Landroid/os/Process;->myPid()I
move-result v0
invoke-static {v0}, Landroid/os/Process;->killProcess(I)V
:cond_0
希望得到的smali文件
.class public Lcom/example/hellowrld/MainActivity;
.super Landroid/app/Activity;
# direct methods
.method public constructor <init>()V
.locals 0
invoke-direct {p0}, Landroid/app/Activity;-><init>()V
return-void
.end method
# virtual methods
.method protected onCreate(Landroid/os/Bundle;)V
.locals 2
invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V
const/high16 v0, 0x7f03
invoke-virtual {p0, v0}, Lcom/example/hellowrld/MainActivity;->setContentView(I)V
invoke-virtual {p0}, Lcom/example/hellowrld/MainActivity;->getApplicationInfo()Landroid/content/pm/ApplicationInfo;
move-result-object v0
iget v1, v0, Landroid/content/pm/ApplicationInfo;->flags:I
and-int/lit8 v1, v1, 0x2
iput v1, v0, Landroid/content/pm/ApplicationInfo;->flags:I
if-eqz v1, :cond_0
invoke-static {}, Landroid/os/Process;->myPid()I
move-result v0
invoke-static {v0}, Landroid/os/Process;->killProcess(I)V
:cond_0
return-void
.end method
.method public onCreateOptionsMenu(Landroid/view/Menu;)Z
.locals 2
invoke-virtual {p0}, Lcom/example/hellowrld/MainActivity;->getMenuInflater()Landroid/view/MenuInflater;
move-result-object v0
const/high16 v1, 0x7f07
invoke-virtual {v0, v1, p1}, Landroid/view/MenuInflater;->inflate(ILandroid/view/Menu;)V
const/4 v0, 0x1
return v0
.end method
修改之前的smali文件
.class public Lcom/example/hellowrld/MainActivity;
.super Landroid/app/Activity;
# direct methods
.method public constructor <init>()V
.locals 0
invoke-direct {p0}, Landroid/app/Activity;-><init>()V
return-void
.end method
# virtual methods
.method protected onCreate(Landroid/os/Bundle;)V
.locals 1
invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V
const/high16 v0, 0x7f03
invoke-virtual {p0, v0}, Lcom/example/hellowrld/MainActivity;->setContentView(I)V
return-void
.end method
.method public onCreateOptionsMenu(Landroid/view/Menu;)Z
.locals 2
invoke-virtual {p0}, Lcom/example/hellowrld/MainActivity;->getMenuInflater()Landroid/view/MenuInflater;
move-result-object v0
const/high16 v1, 0x7f07
invoke-virtual {v0, v1, p1}, Landroid/view/MenuInflater;->inflate(ILandroid/view/Menu;)V
const/4 v0, 0x1
return v0
.end method
作者: terse 时间: 2014-5-21 01:23
- @echo off
- set "s=invoke-virtual {p0, v0}, Lcom/example/hellowrld/MainActivity;->setContentView(I)V"
- (for /f "delims=" %%i in ('findstr /n .* "MainActivity.smali"') do (
- set "str=%%i"
- setlocal enabledelayedexpansion
- set "str=!str:*:=!"
- if defined str (
- for /f "tokens=*" %%j in ("!str!") do (
- echo !str!
- if /i "%%j" == "!s!" type "importent.txt"
- )
- )else echo.
- endlocal
- ))>tem.t
- move tem.t MainActivity.smali
- pause
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |