Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
unix sed仅在存在整个单词时替换行_Unix_Sed - Fatal编程技术网

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想要替换匹配模式的行,而不是完全删除它们。是的,检查了(现在)。更新了我的帖子