我想替换一行中不匹配的部分。例如,我有来自 grep 的一行:
./XYZ/SportsDataManager.m:static NSString* REDEEM_SPORT_CREDIT_URL = @"http://example.com/clients/XYZ/services/sports/prod/prod_sportRedeemUserCredit.php";
从我读过的内容来看,最好通过 sed 进行管道传输。我想删除除 url 之外的所有内容。怎么可能做到这一点?
例如,我会将 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
使用 sed,如果你总是有双引号内的 URL:
sed -n 's/[^"]*"\([^"]*\).*/\1/p' input