我想替换不匹配的行的部分。例如,我有一行来自grep:
./XYZ/SportsDataManager.m:static NSString* REDEEM_SPORT_CREDIT_URL = @"http://example.com/clients/XYZ/services/sports/prod/prod_sportRedeemUserCredit.php";
从我读过的内容来看,最好通过sed管道。除了网址,我想删除所有内容。怎么可以这样做?
答案 0 :(得分:1)
我会使用egrep和-o,例如
echo "./XYZ/SportsDataManager.m:static NSString* REDEEM_SPORT_CREDIT_URL = @\"http://example.com/clients/XYZ/services/sports/prod/prod_sportRedeemUserCredit.php\";" | egrep 'http://.*?\.php' -o
http://example.com/clients/XYZ/services/sports/prod/prod_sportRedeemUserCredit.php
答案 1 :(得分:0)
如果您始终在双引号内使用网址,请使用sed:
sed -n 's/[^"]*"\([^"]*\).*/\1/p' input