Vijesh Kk Vijesh Kk - 1 month ago 5
Bash Question

How to remove a column of lines if it had a word

I want to remove a a column in the line if the search key word exists within that column.

My input will be multi line input, some thing like and column delimiter is ":"

:I want to remove a : column in the line : if the search key word exists within : that column
:I will : be using : word as : the key word
:colon will : be used : as the : delimiter


and search keyword is
word


My output should be

:I want to remove a : column in the line : that column:
:I will : be using :
:colon will : be used : as the : delimiter


Hopes somebody can help me. thanks.

PS. PS.
Answer

Sample input:

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

awk solution:

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

Explanation:

Use RS as ":" ,will make awk to consider each record is separated by ":". Then print that record which does not contains the keyword word and then keep output records separated by ":".

Comments