特定のパターンに一致する行をbashスクリプトの空白行に置き換えるにはどうすればよいですか?
例えば:
-hello:world:this
-is:an:example
-good:morning:
is
次に、パラメータとを使用してスクリプトを起動しますan
。期待される出力は次のとおりです。
-hello:world:this:
-good:morning:
sed 's/^.*is:an.*$//'
あなたは:で置換を行うでしょう
$ cat file
^[[A-hello:world:this
-is:an:example
-good:morning:
$ sed 's/^.*is:an.*$//' file
-hello:world:this
-good:morning:
説明:
sedで置換するs/regexp/replace/
と、正規表現に一致する行の任意の部分が置換され、。に置き換えられreplace
ます。
正規表現^.*is:an.*$
は、文字列を含むすべての行に一致し、is:an
それを何にも置き換えません。