标题: [文本处理] 这段文本应该怎么用批处理替换呢? [打印本页]
作者: zhouyao800 时间: 2013-10-22 21:33 标题: 这段文本应该怎么用批处理替换呢?
a.txt 为以下:
/cntrl_3541_1_828631825
/bk_3541_1_8286318334
/bk_3541_1_828631826
/al_3541_1_828631826
/cntrl_3541_1_828631824
/bk_3541_1_8286318333
/bk_3541_1_8286318262
/al_3541_1_82863182611
b.txt为以下:
chmod 666 $RMAN_LOG_FILE
echo Script $0 >> $RMAN_LOG_FILE
echo ==== started on `date` ==== >> $RMAN_LOG_FILE
echo >> $RMAN_LOG_FILE
ORACLE_HOME=/oracle/product/10.2.0
export ORACLE_HOME
ORACLE_SID=tjtsyw
export ORACLE_SID
ORACLE_USER=oracle
TARGET_CONNECT_STR=sys/Abcd1234
RMAN=$ORACLE_HOME/bin/rman
echo >> $RMAN_LOG_FILE
echo "RMAN: $RMAN" >> $RMAN_LOG_FILE
echo "ORACLE_SID: $ORACLE_SID" >> $RMAN_LOG_FILE
echo "ORACLE_USER: $ORACLE_USER" >> $RMAN_LOG_FILE
echo "ORACLE_HOME: $ORACLE_HOME" >> $RMAN_LOG_FILE
CMD_STR="
ORACLE_HOME=$ORACLE_HOME
export ORACLE_HOME
ORACLE_SID=$ORACLE_SID
export ORACLE_SID
$RMAN target $TARGET_CONNECT_STR nocatalog msglog $RMAN_LOG_FILE append << EOF
RUN {
shutdown immediate;
startup nomount;
allocate channel ch00 type 'sbt_tape';
send 'NB_ORA_CLIENT=tjtsyw1';
send 'NB_ORA_SERV=NBUserver';
restore controlfile from '/cntrl_3541_1_828631826';
release channel ch00;
alter database mount;
编写什么样的批处理能实现把a.txt中的第一行复制出来 替换b.txt中restore controlfile from '/cntrl_3541_1_828631826'这句话中from后面单引号里面的内容呢?替换完了生成c.txt
作者: Lumiere 时间: 2013-10-22 21:55
回复 1# zhouyao800
看不出来你这个批处理有何意义
作者: tmplinshi 时间: 2013-10-22 22:36
本帖最后由 tmplinshi 于 2013-10-22 22:56 编辑
- @echo off
- setlocal
-
- set listFile="a.txt"
- set inFile="b.txt"
- set outFile="c.txt"
-
- set /p Line1=<%listFile%
-
- (
- for /f "tokens=*" %%a in (' findstr /n .* %inFile% ') do (
- set ThisLine=%%a
-
- setlocal enabledelayedexpansion
-
- if "!ThisLine:restore controlfile from '=!" neq "!ThisLine!" (
- for /f "delims='" %%a in ("!ThisLine!") do (
- set ThisLine=%%a'!Line1!';
- )
- )
- echo,!ThisLine:*:=!
-
- endlocal
- )
- ) >%outFile%
复制代码
或者用 sed:- set /p Line1=<a.txt
- sed -r "s|(restore controlfile from )'[^']+'|\1'%Line1%'|ig" b.txt >c.txt
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |