Question about regular expressions

Damien Fleuriot ml at my.gd
Thu Jul 21 14:48:07 UTC 2011



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 at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at 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.


More information about the freebsd-questions mailing list