in reply to Re: Capturing the nth word in a string
in thread Capturing the nth word in a string
[me@host bin]$ perl -we '$n = $ARGV[0]; $_ = "a b csadf sdfas ddd"; /( +?:\S+\s+){@{[$n-1]}}(\S+)/; print "$1\n"' 1 a [me@host bin]$ perl -we '$n = $ARGV[0]; $_ = "a b csadf sdfas ddd"; /( +?:\S+\s+){@{[$n-1]}}(\S+)/; print "$1\n"' 2 b [me@host bin]$ perl -we '$n = $ARGV[0]; $_ = "a b csadf sdfas ddd"; /( +?:\S+\s+){@{[$n-1]}}(\S+)/; print "$1\n"' 4 sdfas [me@host bin]$
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Capturing the nth word in a string
by pg (Canon) on Oct 14, 2003 at 05:16 UTC | |
by etcshadow (Priest) on Oct 29, 2003 at 22:09 UTC |