in reply to How to substitute all tabs only in a specific field
G'day Xuo,
There are a lot a problems with your post:
Please read "How do I post a question effectively?" carefully.
So, with a lot of guessswork, I believe the following technique, succinctly and efficiently, does what you want:
$ perl -pE 's/^[^"]+"\s+(.+)\s+"/$1 =~ y{ \t}{,}rs/e' a b " x1 x2 " x1,x2 c d " x3 " x3 e f " x4 x5 x6 x7 " x4,x5,x6,x7 x y z " 1space 2spaces spacetabspace end " 1space,2spaces,spacetabspace,end
The 'r' modifier was introduced in Perl v5.14: see "perl5140delta: Non-destructive substitution". Attempting to modify $1 directly results in a "Modification of a read-only value" fatal error. If you have a earlier version of Perl, you'll need to use an interim variable; perhaps something like this:
$ perl -pe 's/^[^"]+"\s+(.+)\s+"/($x = $1) =~ y{ \t}{,}s; $x/e' a b " x1 x2 " x1,x2 c d " x3 " x3 e f " x4 x5 x6 x7 " x4,x5,x6,x7 x y z " 1space 2spaces spacetabspace end " 1space,2spaces,spacetabspace,end
— Ken
|
|---|