我试图在文本文件中找到一些只以一个(+)开头的行。
我的档案:
--- step31.php 2017-03-10 18:34:59.430949110 +0330
+++ step32.php 2017-03-10 18:34:59.430949110 +0330
@@ -1,6 +1,6 @@
<?php
defined('_JEXEC') or die;
-JLoader::register('BannersHelper', JPATH_COMPONENT . '/helpers/banners.php');
+JLoader::register('BannersHelper', JPATH_ADMINISTRATOR . '/components/com_banners/helpers/banners.php');
class BannersViewBanner extends JViewLegacy{
protected $form;
protected $item;
@@ -32,7 +32,7 @@
JToolbarHelper::save2copy('banner.save2copy');}
if (empty($this->item->id)) {
JToolbarHelper::cancel('banner.cancel');} else {
- if ($this->state->params->get('save_history', 0) && $user->authorise('core.edit')) {
+ if ($this->state->params->get('save_history', 0) && $canDo->get('core.edit')) {
JToolbarHelper::versions('com_banners.banner', $this->item->id);}
期望的输出:
+JLoader::register('BannersHelper', JPATH_ADMINISTRATOR . '/components/com_banners/helpers/banners.php');
+ if ($this->state->params->get('save_history', 0) && $canDo->get('core.edit')) {
我使用grep '^+'
但输出为:
+++ step32.php 2017-03-10 18:34:59.430949110 +0330
+JLoader::register('BannersHelper', JPATH_ADMINISTRATOR . '/components/com_banners/helpers/banners.php');
+ if ($this->state->params->get('save_history', 0) && $canDo->get('core.edit')) {
答案 0 :(得分:1)
您可以使用:
grep '^+[^+]' file
+JLoader::register('BannersHelper', JPATH_ADMINISTRATOR . '/components/com_banners/helpers/banners.php');
+ if ($this->state->params->get('save_history', 0) && $canDo->get('core.edit')) {
正则表达式^+[^+]
将在开始时匹配+
,然后是除+
之外的任何内容,从而为您提供预期的输出。