From owner-freebsd-questions@FreeBSD.ORG Thu Jul 21 14:48:07 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 94E64106566B for ; Thu, 21 Jul 2011 14:48:07 +0000 (UTC) (envelope-from ml@my.gd) Received: from mail-wy0-f182.google.com (mail-wy0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 2D3B68FC1D for ; Thu, 21 Jul 2011 14:48:06 +0000 (UTC) Received: by wyg24 with SMTP id 24so1180859wyg.13 for ; Thu, 21 Jul 2011 07:48:06 -0700 (PDT) Received: by 10.227.29.150 with SMTP id q22mr277950wbc.78.1311259686124; Thu, 21 Jul 2011 07:48:06 -0700 (PDT) Received: from dfleuriot-at-hi-media.com ([83.167.62.196]) by mx.google.com with ESMTPS id gb1sm1112505wbb.37.2011.07.21.07.48.04 (version=SSLv3 cipher=OTHER); Thu, 21 Jul 2011 07:48:05 -0700 (PDT) Message-ID: <4E283C23.1060305@my.gd> Date: Thu, 21 Jul 2011 16:48:03 +0200 From: Damien Fleuriot User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: freebsd-questions@freebsd.org References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: Question about regular expressions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jul 2011 14:48:07 -0000 On 7/21/11 4:33 AM, dave jones wrote: > Hi, > > I have a config file below: > > $user = 'root'; // This is the username > > if $user is found, I want to display root. > Anyone knows how to programming in C or some other language? thank you. > > Regards, > Dave. > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" Let us assume you want to read your file, then display each entry for "$user1" , "$user2" and so on: grep "$user" my_file | awk '{ print $3}' | sed -e "s/\'//" | sed -e "s/;//" 1/ open my_file and only display lines containing "$user" 2/ display the 3rd item on the line 3/ remove the single quotes and the ; I'm sure it can be optimized a bit but basically, that'll do what I assume you want.