Re: OT: string manipulation. sed? gawk? other? how?
On Wed, Oct 12, 2011 at 6:50 AM, Kent West <westk@acu.edu> wrote:
> On 10/11/2011 05:27 PM, Chris Davies wrote:
>>
>> On 10/11/2011 03:20 PM, John L. Cunningham wrote:
>>>
>>> johnc@infotech:~$ cat lazydog.awk
>>> /^The lazy dog/{
>>> if ( count< 1 ){
>>> print "The lazy dog is my favorite."
>>> count++
>>> next
>>> } else {
>>> next
>>> }
>>> }
>>> {
>>> print
>>> }
>>
>> This works, but for those that are interested, and at the risk of making
>> the script harder for some people to read, it can be simplified
>
> <snip>
>>
>> awk '/^The lazy dog/{if(!k++){print"The lazy dog is my
>> favourite."};next}1'
>>
>
> Oooh, I like that! (except there appears to be a typo in "favorite" ;-)
> (wait, didn't we already do the British-American English off-topic
> thread?))
>
Try perl, it's lovely too.
perl -ne 'print $_ unless (s/^(The lazy dog).*/$1 is my favorite./ and $k++)'
Alexey Salmin
Reply to: