开发者

How do I remove a line of the form ARRAY=...; with sed?

I'm trying to learn sed, but I encountered a problem. Let me explain, I have a file called in:

code..
ARRAY=(anystring);
code..

where anystring means that there can be the code I want to, since it's only an example. Now with sed i want to remove the line "ARRAY=...;"

I tried with:

sed "/#ARRAY=.*;/d" in > out

But with no success, while:

sed "/ARRAY=[a-z]*;/d" in > out

Is working fine for me. The problem is that after "AR开发者_运维百科RAY=" there can be all the characters (except of ; obviously).

How can I do this?


Try this:

sed '/^ARRAY=.*;/d' in >out

The beginning of the line is expressed as ^, not #. If you accept leading whitespace, as suggested by Swiss in the comment, use

sed '/^[ \t]*ARRAY=.*;/d' in >out


Remove the '#' character in the first command. The '#' character has no special meaning in sed regex.


sed "s/^ARRAY=.*;//g" <in >out Or better yet sed "/^ARRAY=.*;/d" <in >out

The "s" means, substitute. So s/ABC/DEF/ means replace ABC with DEF. The "g" means global, so it will remove all such lines, instead of only the first one. ^ means, the line must begin with ARRAY

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜