awk question

Alex Zbyslaw xfb52 at dial.pipex.com
Tue Mar 7 14:12:16 UTC 2006


Bart Silverstrim wrote:

>
> On Mar 6, 2006, at 4:45 PM, Noel Jones wrote:
>
>> On 3/6/06, Bart Silverstrim <bsilverstrim at athensasd.org> wrote:
>>
>>> I'm totally drawing a blank on where to start out on this.
>>>
>>> If I have a list of URLs like
>>> http://www.happymountain.com/archive/digest.gif
>>>
>>> How could I use Awk or Sed to strip everything after the .com?  Or is
>>> there a "better" way to do it?  
>>
>>
>>     | cut -d / -f 1-3
>
>
> Oh boy was that one easy.  It was a BAD mental hiccup.
>
> I'll add a sort and uniq and it should be all ready to go. Thanks!
>

More than one way to skin that cat!  cut is nice'n'easy but since you 
asked about awk and sed, these would work too:


awk -F/ 'NF > 2 {printf "%s//%s\n",  $1, $3}'

or

sed 's,^\([^/]*://[^/]*\).*,\1,'

--Alex




More information about the freebsd-questions mailing list