The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting a substring starting from last occurance of a string/character krramkumar Shell Programming and Scripting 2 12-19-2007 03:16 AM
String search - Command to find second occurance saurabhsinha23 UNIX for Dummies Questions & Answers 5 12-06-2007 08:03 PM
count string occurance in a file hourly ayhanne UNIX for Dummies Questions & Answers 2 10-13-2007 10:47 AM
string replacing priya_9patil Shell Programming and Scripting 1 11-03-2006 12:05 PM
Removing the last occurance of string dkhanna01 Shell Programming and Scripting 7 12-28-2004 05:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-13-2008
vivekshady vivekshady is offline
Registered User
  
 

Join Date: May 2008
Posts: 1
Replacing Last occurance of & from a string

Hi All,

Could anyone help me out in the below requirement:

I have a text(XML) file like this:

Code:
- <Dim2>
  <Properties Name="[Customers]" State="2" ShowHir="-1" ApplyFilter="-1" ExpandToLevel="1" BreakHierType="1" MaxDepth="1" SlicerSelectOptions="1" ShowLeaf="0" HasGroup="0" /> 
  <Expanded Value="Pn0102{}[Customers].[Parent Name].&[All Customers]{}0{}[Customers].[All Customers]{}0" /> 
  <Hidden Value="Pn0102{}[Customers].[Parent Name].&[C_Unmatched Outpayments]{}0{}[Customers].[Parent Name].&[ITXC Corporation]{}0{}[Customers].[Parent Name].&[Teleglobe Corporation]{}0{}[Customers].[Parent Name].&[Teleglobe Inter-Company]{}0" /> 
- <Filter>
  <Properties DimName="[Customers]" UseFilter="0" /> 
- <ByName>
  <Properties Count="1" /> 
  <Names Value="Pn0102{}Members{}0" /> 
- <Item1>
  <Properties Name="Members" FilterType="0" Members="Pn0102{}[Customers].[Parent Name].&[All Customers].&[NEOTEL / NEOTEL (PRIME)]{}0{}[Customers].[Parent Name].&[All Customers].&[NEOTEL/CELL-C (PRIME)]{}0{}[Customers].[Parent Name].&[All Customers].&[NEOTEL/DIGITAL INDABA]{}0{}[Customers].[Parent Name].&[All Customers].&[NEOTEL/LEVIN GLOBAL]{}0{}[Customers].[Parent Name].&[All Customers].&[NEOTEL/MTN (PRIME)]{}0{}[Customers].[Parent Name].&[All Customers].&[NEOTEL/SYRINX COMMUNICATIONS INTERNATIONAL (PTY) LTD]{}0{}[Customers].[Parent Name].&[All Customers].&[NEOTEL/VODACOM (PRIME)]{}0" IncludeMember="-1" ExcludeFilter="0" AndFilter="0" Prefix="0" Suffix="0" Enabled="-1" /> 
  <ValueFilter Activated="0" IsGridFilter="0" AxisType="0" Members="Pn0102{}" FilterType0="8" Value0="5" Value10="0" IsAnd0="0" IsVisible0="-1" IsEnabled0="-1" MaxValue0="10" MinValue0="1" Step0="1" Enabled0="0" FilterType1="8" Value1="0" Value11="0" IsAnd1="0" IsVisible1="0" IsEnabled1="-1" MaxValue1="10" MinValue1="1" Step1="1" Enabled1="0" FilterType2="8" Value2="0" Value12="0" IsAnd2="0" IsVisible2="0" IsEnabled2="-1" MaxValue2="10" MinValue2="1" Step2="1" Enabled2="0" /> 
  <ValueFilterSort Direction="0" Members="Pn0102{}" /> 
  </Item1>
  </ByName>
  </Filter>
  </Dim2>

In this file, i need to do the following:

Find the occurance of [Customers].*]{}0 and replace the last occurance of & between [Customers].*]{}0

where * could be any text


and hence my output should look like:

Code:
- <Dim2>
  <Properties Name="[Customers]" State="2" ShowHir="-1" ApplyFilter="-1" ExpandToLevel="1" BreakHierType="1" MaxDepth="1" SlicerSelectOptions="1" ShowLeaf="0" HasGroup="0" /> 
  <Expanded Value="Pn0102{}[Customers].[Parent Name].[All Customers]{}0{}[Customers].[All Customers]{}0" /> 
  <Hidden Value="Pn0102{}[Customers].[Parent Name].[C_Unmatched Outpayments]{}0{}[Customers].[Parent Name].[ITXC Corporation]{}0{}[Customers].[Parent Name].[Teleglobe Corporation]{}0{}[Customers].[Parent Name].[Teleglobe Inter-Company]{}0" /> 
- <Filter>
  <Properties DimName="[Customers]" UseFilter="0" /> 
- <ByName>
  <Properties Count="1" /> 
  <Names Value="Pn0102{}Members{}0" /> 
- <Item1>
  <Properties Name="Members" FilterType="0" Members="Pn0102{}[Customers].[Parent Name].&[All Customers].[NEOTEL / NEOTEL (PRIME)]{}0{}[Customers].[Parent Name].&[All Customers].[NEOTEL/CELL-C (PRIME)]{}0{}[Customers].[Parent Name].&[All Customers].[NEOTEL/DIGITAL INDABA]{}0{}[Customers].[Parent Name].&[All Customers].[NEOTEL/LEVIN GLOBAL]{}0{}[Customers].[Parent Name].&[All Customers].[NEOTEL/MTN (PRIME)]{}0{}[Customers].[Parent Name].&[All Customers].[NEOTEL/SYRINX COMMUNICATIONS INTERNATIONAL (PTY) LTD]{}0{}[Customers].[Parent Name].&[All Customers].[NEOTEL/VODACOM (PRIME)]{}0" IncludeMember="-1" ExcludeFilter="0" AndFilter="0" Prefix="0" Suffix="0" Enabled="-1" /> 
  <ValueFilter Activated="0" IsGridFilter="0" AxisType="0" Members="Pn0102{}" FilterType0="8" Value0="5" Value10="0" IsAnd0="0" IsVisible0="-1" IsEnabled0="-1" MaxValue0="10" MinValue0="1" Step0="1" Enabled0="0" FilterType1="8" Value1="0" Value11="0" IsAnd1="0" IsVisible1="0" IsEnabled1="-1" MaxValue1="10" MinValue1="1" Step1="1" Enabled1="0" FilterType2="8" Value2="0" Value12="0" IsAnd2="0" IsVisible2="0" IsEnabled2="-1" MaxValue2="10" MinValue2="1" Step2="1" Enabled2="0" /> 
  <ValueFilterSort Direction="0" Members="Pn0102{}" /> 
  </Item1>
  </ByName>
  </Filter>
  </Dim2>

This is very much required to fix an issue asap. Early resolution would be very very helpful to me.

Thanks,
Vivekshady

Last edited by Yogesh Sawant; 05-14-2008 at 01:24 AM.. Reason: added code tags
  #2 (permalink)  
Old 05-13-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Try this:

Code:
perl -pe 's/([[]Customers[]].*?)&([^&]+?{}0)/$1$2/g' input
This part matches the [Customers] prefix, saved in $1. The *? means not to be greedy, otherwise it would match the whole line:

([[]Customers[]].*?)

This part matches the final &:

&

This part matches the remaining non-& characters before the next {}0, saved in $1. Once again, +? means one or more occurrences, but not greedily:

([^&]+?{}0)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0