Date: Thu, 21 Jul 2011 16:48:03 +0200 From: Damien Fleuriot <ml@my.gd> To: freebsd-questions@freebsd.org Subject: Re: Question about regular expressions Message-ID: <4E283C23.1060305@my.gd> In-Reply-To: <CANf5e8ZfbcNdkjgfBvektTe7rkOdj0P1Le7tAC59D2tunq%2BFAA@mail.gmail.com> References: <CANf5e8ZfbcNdkjgfBvektTe7rkOdj0P1Le7tAC59D2tunq%2BFAA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4E283C23.1060305>