Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.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
Bash 如何删除包含单词的行列_Bash_Perl_Shell_Awk_Sed - Fatal编程技术网

Bash 如何删除包含单词的行列

Bash 如何删除包含单词的行列,bash,perl,shell,awk,sed,Bash,Perl,Shell,Awk,Sed,如果该行中存在搜索关键字,我想删除该行中的a列 我的输入将是多行输入,例如和列分隔符: 搜索关键字是word 我的输出应该是 :I want to remove a : column in the line : that column: :I will : be using : :colon will : be used : as the : delimiter :[^:::*表示:后跟零个或多个非:字符 要匹配的字串 [^:::*零个或多个非:字符 因为replacement是空的,所以匹配

如果该行中存在搜索关键字,我想删除该行中的a列

我的输入将是多行输入,例如和列分隔符:

搜索关键字是word

我的输出应该是

:I want to remove a : column in the line : that column:
:I will : be using :
:colon will : be used : as the : delimiter
:[^:::*表示:后跟零个或多个非:字符 要匹配的字串 [^:::*零个或多个非:字符 因为replacement是空的,所以匹配的字符串被有效地删除 请注意,这将只删除第一个这样的匹配项 :[^:::*表示:后跟零个或多个非:字符 要匹配的字串 [^:::*零个或多个非:字符 因为replacement是空的,所以匹配的字符串被有效地删除 请注意,这将只删除第一个这样的匹配项 Perl解决方案:

 echo $x |awk -v RS=":" -v ORS=:  '!/word/'
:I want to remove a : column in the line : that column:
Perl解决方案:

 echo $x |awk -v RS=":" -v ORS=:  '!/word/'
:I want to remove a : column in the line : that column:
样本输入:

echo $x
:I want to remove a : column in the line : if the search key word exists within : that column:
awk解决方案:

 echo $x |awk -v RS=":" -v ORS=:  '!/word/'
:I want to remove a : column in the line : that column:
说明:

使用RS作为,将使AWK考虑每个记录由:然后打印不包含关键字的记录,然后将输出记录用以下分隔:。

示例输入:

echo $x
:I want to remove a : column in the line : if the search key word exists within : that column:
awk解决方案:

 echo $x |awk -v RS=":" -v ORS=:  '!/word/'
:I want to remove a : column in the line : that column:
说明:

使用RS作为,将使AWK考虑每个记录由:然后打印不包含关键字单词的记录,然后将输出记录用以下分隔:。

Perl代码: Perl代码:
这很好,最适合我的要求。谢谢你的帮助。我尝试了多行输入,我发现只要搜索关键字在最后一列,下一行就会被追加到修改过的行中。是否有办法保留换行符中的下一行。@VijeshKk最好修改您的问题,使其包含多行输入文件和预期输出…我同意Sundeep,需要示例输入来修改我们的命令。这很好,最适合我的要求。谢谢你的帮助。我尝试了多行输入,我发现只要搜索关键字在最后一列,下一行就会被追加到修改过的行中。是否有办法保留换行符中的下一行。@VijeshKk最好修改您的问题,使其包含多行输入文件和预期输出…我同意Sundeep,需要示例输入来修改我们的命令。与以前的版本相比,您的输入行不以:结尾。。这实际上成了一个新问题。。考虑添加到这个版本,并问一个新的问题,如果你不能修改解决方案,也提到如果你需要删除所有列匹配搜索关键字,或只有第一匹配你的输入线不结束:与以前的版本相比…这实际上成了一个新问题。。考虑添加到这个版本,并问一个新的问题,如果你不能修改解决方案,也提到如果你需要删除所有列匹配搜索关键字或只有第一个匹配