in reply to Re^2: How can I replace the pattern in the 6 th field?
in thread How can I replace the pattern in the 6 th field?
If whitespace actually is the field delimiter, another way to operate on only the seventh field of the entire record without first extracting all fields would be this (needs Perl version 5.14+):
Whether this is faster/better than a split/join approach is left as an exercise for theravadamonk; I doubt it really is. (This approach requires Perl version 5.14+ due to use of the /r modifier in the tr/// operator and version 5.10+ for the \K regex operator. These can be avoided in earlier versions of Perl fairly simply; let me know if a workaround is needed. (Update: See this reply for workarounds.))c:\@Work\Perl\monks>perl -wMstrict -le "use 5.014; ;; my $rec = 'Jun 12 10 mail (sender@sender.com) - (recip1@domain.com),(recip2@d +omain.com) -1.889 25623, queued_as: B67837C0052 Subject goes here Sen +der(sender@sender.com)'; print qq{'$rec'}; ;; $rec =~ s{ \A \s* (?: \S+ \s+){6} \K (\S+) }{ $1 =~ tr/()//dr }xmse; print qq{'$rec'}; " 'Jun 12 10 mail (sender@sender.com) - (recip1@domain.com),(recip2@doma +in.com) -1.889 25623, queued_as: B67837C0052 Subject goes here Sender +(sender@sender.com)' 'Jun 12 10 mail (sender@sender.com) - recip1@domain.com,recip2@domain. +com -1.889 25623, queued_as: B67837C0052 Subject goes here Sender(sen +der@sender.com)'
Give a man a fish: <%-{-{-{-<
|
|---|