我试图从源代码中提取信息以创建一个API供其他人使用。我可以通过grep来获取具有共同特征的变量列表,但某些变量是多态的,所以我不能很好地清除它们。使用sed删除具有通用前缀的单词
例如:
public static Foo bar = new Foo(123, "Bar");
public static Foo baz = new Foo(222, "Baz");
public static FooBar fBar = new FooBar(135, "Foo", "Bar");
public static FooBaz fBaz = new FooBaz(256, "Baz", "Badger", "Baz");
我想下简化为:
bar 123 Bar
baz 222 Baz
fBar 135 Bar
fBaz 256 Baz
目前,我到目前为止已经做到了这一点:
grep "public static Foo" file.java | tr '(' ' ' | tr ')' ' ' | sed "s/public\ static\ //g"
这给了我这个:
Foo bar = new Foo 123, "Bar" ;
Foo baz = new Foo 222, "Baz" ;
FooBar fBar = new FooBar 135, "Foo", "Bar" ;
FooBaz fBaz = new FooBaz 256, "Baz", "Badger", "Baz" ;
当我试图链接它与sed "s/Foo*\ //g"
,它不会删除单词FooBar和FooBaz。我怎么能纠正这个问题呢?还是有更好的方法来实现我想要做的事情?
:
你的榜样,你只需选择第一个和最后一个参数? – Kent 2013-05-02 16:30:33