English 中文(简体)
a. 采用印本书写法,在行文中添加一条具体内容
原标题:To Find a Particular line and copying a specific content within the line using bash scripting
  • 时间:2012-05-09 09:18:35
  •  标签:
  • bash

我有档案系统。

BEGIN lmb_bram_if_cntlr
PARAMETER INSTANCE = dlmb_cntlr_0
PARAMETER HW_VER = 3.00.b
PARAMETER C_BASEADDR = 0x00000000
PARAMETER C_HIGHADDR = 0x0003ffff
BUS_INTERFACE SLMB = dlmb_0
BUS_INTERFACE BRAM_PORT = calmb_0_BRAM_PORTA
END

BEGIN lmb_bram_if_cntlr
PARAMETER INSTANCE = ilmb_cntlr_0
PARAMETER HW_VER = 3.00.b
PARAMETER C_BASEADDR = 0x00000000
PARAMETER C_HIGHADDR = 0x0003ffff
BUS_INTERFACE SLMB = ilmb_0
BUS_INTERFACE BRAM_PORT = ilmb_cntlr_0_BRAM_PORT
END

BEGIN lmb_bram_if_cntlr
PARAMETER INSTANCE = dlmb_cntlr_1
PARAMETER HW_VER = 3.00.b
PARAMETER C_BASEADDR = 0x00000000
PARAMETER C_HIGHADDR = 0x0000ffff
BUS_INTERFACE SLMB = dlmb_1
BUS_INTERFACE BRAM_PORT = calmb_1_BRAM_PORTA
END

BEGIN lmb_bram_if_cntlr
PARAMETER INSTANCE = ilmb_cntlr_1
PARAMETER HW_VER = 3.00.b
PARAMETER C_BASEADDR = 0x00000000
PARAMETER C_HIGHADDR = 0x0000ffff
BUS_INTERFACE SLMB = ilmb_1
BUS_INTERFACE BRAM_PORT = ilmb_cntlr_1_BRAM_PORT
END

我想复制PARAMETER C_HIGHADDR = (数值)只适用于PARAMETER INSTTRI = ilmb_cntlr_n

注:这类内容可以有少量,但只希望复制该地址。

如何做到这一点?

地址一经复制,例如0x0003ff, 即希望将其复制为0x0003FFB0

the last two ff are replace by B0

由F取代,其他地址保持不变。

如何做到这一点?

问题回答

这里的解决办法是:

while read line ; do
    if [[ $line =~ ^PARAMETER INSTANCE = ilmb_cntlr_[0-9] ]] ; then
        found=1
    fi
    if [[ $line =~ ^PARAMETER C_HIGHADDR =  ]] ; then
        value=$line
    fi
    if [[ $line =    ]] ; then                      # end of block
        if (($found)) ; then                        # we are interested in the block
            value=${value//f/F}                     # capitalize f s
            echo ${value%FF}B0                      # replace last two characters with B0
        fi
        unset found                                 # reset variables so we can check the next block
        unset value
    fi
done

但我想用Perl来完成这项任务。





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签