unix sed仅在存在整个单词时替换行
我一篇课文有三行unix sed仅在存在整个单词时替换行,unix,sed,Unix,Sed,我一篇课文有三行 clm\u id加倍, 双重身份证, clm_id int, 我想替换整个单词clm_id出现在下面的行 clm_id bigint, 双重身份证, clm_id bigint, 任何指针?您可以使用以下命令: sed 's/.*\(^\| \)clm_id\( \|$\).*/clm_id bigint/' input.file 说明: / Delimiter .* Anything (optional) \(^\| \) Select
clm\u id加倍,
双重身份证,
clm_id int,
我想替换整个单词clm_id出现在下面的行
clm_id bigint,
双重身份证,
clm_id bigint,
任何指针?您可以使用以下命令:
sed 's/.*\(^\| \)clm_id\( \|$\).*/clm_id bigint/' input.file
说明:
/ Delimiter
.* Anything (optional)
\(^\| \) Selects the beginning of the line `^` or `|` a whitespace before the word.
into a capturing group (Note that `(|)` need to get escaped by a `\'
clm_id Selects clm_id
\( \|$\) ... followed by a whitespace or the end of the line `$`
.* Anything (optional)
/ Delimiter
clm_id bigint
actv_clm_id double
clm_id bigint
输出:
/ Delimiter
.* Anything (optional)
\(^\| \) Selects the beginning of the line `^` or `|` a whitespace before the word.
into a capturing group (Note that `(|)` need to get escaped by a `\'
clm_id Selects clm_id
\( \|$\) ... followed by a whitespace or the end of the line `$`
.* Anything (optional)
/ Delimiter
clm_id bigint
actv_clm_id double
clm_id bigint
这可能适用于您(GNU-sed):
sed'/\/c\clm\u id bigint'文件
提供清晰的输入和所需的输出。学习正则表达式。查找sed教程。;)你试过什么吗?这是我尝试的sed-I's/\/c\/clm\u id bigint,/gI'
我认为OP想要替换匹配模式的行,而不是完全删除它们。是的,检查了(现在)。更新了我的帖子