#!/usr/bin/perl -w use strict; my $delimiter = ';'; my $nth = 3; my $regex = '^(' . ".*$delimiter"x$nth . ')'; while (<DATA>) { s/$regex/$1$delimiter/ && print; } __DATA__ col1;col2;col3;col4 aaa;bbb;ccc;ddd AAA;BBB;CCC;DDD
Regards,col1;col2;col3;;col4 aaa;bbb;ccc;;ddd AAA;BBB;CCC;;DDD
In reply to Re: Replacing nth occurrence of string
by svenXY
in thread Replacing nth occurrence of string
by loris
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |