linux - 使用 sed 向特定行添加字符串

标签 linux bash sed

我正在尝试对某些手册页进行一些格式化,我需要添加

] hfill \\

某些标题。我想做这个

NAME
   env - run a program in a modified environment

SYNOPSIS
   env    [-]    [-i]    [-u   name]   [--ignore-environment]
   [--unset=name] [name=value]... [command [args...]]

DESCRIPTION
   This manual page documents the GNU version  of  env.   env
   runs  a  command with an environment modified as specified
   by the command line...

进入这个

\item[NAME] \hfill \\
   env - run a program in a modified environment

\item[SYNOPSIS] \hfill \\
   env    [-]    [-i]    [-u   name]   [-\hspace{.01cm}-ignore-environment]
   [-\hspace{.01cm}-unset=name] [name=value]... [command [args...]]

\item[DESCRIPTION] \hfill \\
   This manual page documents the GNU version  of  env.   env
   runs  a  command with an environment modified as specified
   by the command line...

我得到了“\item[”部分,但出于某种原因我无法得到另一半。我正在使用的命令:

 /[A-Z]/s/$/\] \\hfill \\\\/

有效但出现在我不想要的行上。

最佳答案

试试这个,假设标题只有一行以大写字母开头

sed '/^[A-Z]/ s/.*/\\item[&] \\hfill \\\\/' YourFile

对于 \hspace{.01cm},你应该定义它应该发生的时间(条件)

关于linux - 使用 sed 向特定行添加字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32623385/

相关文章:

django - 制作 : *** [port-target] Error 2 When trying to install GDAL for GeoDjango using Ubuntu 18. 04

bash - 在 Postgres 日志记录机制中更改定界符和换行符

linux - 如何从多列中剪切字符范围

awk - 删除除 2 个匹配模式 Shell 脚本之间的文本之外的所有文本

c++ - Linux 打印 - 操作方法

linux - 在 linux 中写入后崩溃

linux - 不断将控制台的输出写入文件

linux - 如何解析 svn diff 结果?

linux - 从文件中取出某些数据

PHP 无法在带有 nginx 和 php-fpm 的 Amazon EC2 服务器上的页面内工作