Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing duplicate string from same line - if it exists 1

Status
Not open for further replies.

arunrr

Programmer
Oct 2, 2009
103
US
Hello,

I have the following file...

Dec 24, Meeting #32, Newark
Dec 26-Dec 30, Event #6, Birmingham
Dec 26-Dec 30, Event #7, Tampa
Dec 28, Meeting #33, Los Angeles
Dec 30-Jan 2, Event #8, Brussels
Jan 5-Jan 9, Event #9, Bangalore

The resulting out should be...

Dec 24, Meeting #32, Newark
Dec 26-30, Event #6, Birmingham
Dec 26-30, Event #7, Tampa
Dec 28, Meeting #33, Los Angeles
Dec 30-Jan 2, Event #8, Brussels
Jan 5-9, Event #9, Bangalore

In other words, if the date range is 'Dec xx-Dec yy", where the month for both the dates in the range is the same, then I do not need to show the month.

Thanks
AR
 
Hi

Code:
sed 's/\(\([[:alpha:]]\{3\}\) [[:digit:]]\{1,2\}-\)\2 /\1/' /input/file
Tested with GNU [tt]sed[/tt].

If you have no luck with your [tt]sed[/tt] implementation, try to use something else. The substitution should work in any tool/language capable to handle backreferences. Of course, after adjusting the regular expression's syntax.

Feherke.
 
Thanks Feherke, awesome! No surprise you were MVP!!
AR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top