I have a file I need to reformat which contains a string like this:
pin_name[10], pin_name[9], pin_name[8], ..., other_pin_name, some_other_pin_name[1], some_other_pin_name[0]
What I want to obtain is a string like this:
pin_name[10], [9], [8], ..., other_pin_name, some_other_pin_name[1], [0]
So, I want to remove all subsequent duplicate prefixes and leave only the suffix which is different. Any idea?
Thanks!
perl -pe 's/\b((\w+)\[\d+\])((?:,\s*\2\[\d+\])+)/$a=$1;$b=$3;$b=~s,$2,,g;$a.$b/eg'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.