Gop*_*pal 4 sed text-processing
我想在匹配的 PATTERN 之后将 file1 的内容插入到 file2 中。我只想在第一次出现 PATTERN 之后才这样做。
我想知道我需要对以下命令进行哪些修改以满足我的需要。
sed -i "/PATTERN/r file1" file2
Run Code Online (Sandbox Code Playgroud)
sed '/PATTERN/{
r file1
:a
n
ba
}' file2
Run Code Online (Sandbox Code Playgroud)
:a, n,ba只是一个循环,将 PATTERN 之后的整个文件内容打印到最后。请注意,这 6 行只是一个命令,但需要换行符来分隔r,:和之后的下一个 sed 命令b。
附加信息来自info sed:
`n'
If auto-print is not disabled, print the pattern space, then,
regardless, replace the pattern space with the next line of input.
If there is no more input then `sed' exits without processing any
more commands.
`: LABEL'
[No addresses allowed.]
Specify the location of LABEL for branch commands. In all other
respects, a no-op.
`b LABEL'
Unconditionally branch to LABEL. The LABEL may be omitted, in
which case the next cycle is started.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3614 次 |
| 最近记录: |