从匹配模式的行之间的文件中删除行
Remove lines from a file between lines matching a pattern
如果这是我的文件:
This part can stay
START ALPHA
This should be deleted
And this too
END ALPHA
This should stay
START BETA
This should be deleted
END BETA
This should stay
应删除“开始(无论)”和“结束(无论)”行之间的所有内容。
我该怎么做?我可以使用 sed、perl、python,不管用什么。
使用 ed(1)
或 sed(1)
脚本:
$ cat filter.sh
#!/bin/sh
exec sed "/START /,/END /d" data.txt
$ filter.sh ALPHA
This part can stay
This should stay
START BETA
This should be deleted
END BETA
This should stay
$ filter.sh BETA
This part can stay
START ALPHA
This should be deleted
And this too
END ALPHA
This should stay
This should stay
$ _
$
标志就是shell提示,我想你会明白的。 filter.sh
是执行您想要的操作的脚本。
如果这是我的文件:
This part can stay
START ALPHA
This should be deleted
And this too
END ALPHA
This should stay
START BETA
This should be deleted
END BETA
This should stay
应删除“开始(无论)”和“结束(无论)”行之间的所有内容。
我该怎么做?我可以使用 sed、perl、python,不管用什么。
使用 ed(1)
或 sed(1)
脚本:
$ cat filter.sh
#!/bin/sh
exec sed "/START /,/END /d" data.txt
$ filter.sh ALPHA
This part can stay
This should stay
START BETA
This should be deleted
END BETA
This should stay
$ filter.sh BETA
This part can stay
START ALPHA
This should be deleted
And this too
END ALPHA
This should stay
This should stay
$ _
$
标志就是shell提示,我想你会明白的。 filter.sh
是执行您想要的操作的脚本。