![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
Try this:
Code:
perl -pe 's/([[]Customers[]].*?)&([^&]+?{}0)/$1$2/g' input
([[]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) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|