in reply to Re: How to substitute all tabs only in a specific field
in thread How to substitute all tabs only in a specific field

Sorry, but your specifications are still unclear.

Only tabs in the fields between quotes should be replaced by commas.

But your example input doesn't have any tabs. You should copy and paste an actual sample of an input file into the <code> tags.

You also haven't specified whether the quotes can be escaped or not, i.e. whether a b "x1    \"    x2" is valid and should result in a b "x1,\",x2".

I couldn't make it work from the code from Haukex because I don't have Regexp::Common

Yes, even you can use CPAN, and also in the worst case the regular expressions generated from Regexp::Common can be printed on a machine that has it installed, and then used on one that doesn't.

Depending on your actual input file format, maybe your solution can be as simple as:

$ cat in.txt a b "x1 x2" c d "x2" e f "x3 x4 x5" $ perl -ple 's/(?<=")([^"]*)(?=")/(my$x=$1)=~s#\t#,#g;$x/ge' in.txt a b "x1,x2" c d "x2" e f "x3,x4,x5" $ perl -ple 's/(?<=")([^"]*)(?=")/$1=~s#\t#,#gr/ge' in.txt a b "x1,x2" c d "x2" e f "x3,x4,x5"

The second example only works on Perl 5.14+ due to the /r modifier.