LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-09-2015, 07:50 AM   #1
kamleshkk
LQ Newbie
 
Registered: Dec 2015
Posts: 2

Rep: Reputation: Disabled
Unhappy gawk -F: '{if($1="kamlesh") print $0}' /etc/passwd


gawk -F: '{if($1="<user-name>") print $0}' /etc/passwd
Please explain me the output,since it shows around 35-40 lines for a user of name user-name, but /etc/passwd file is having only single entry of that user.so from where all these lines come.
 
Old 12-09-2015, 08:07 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
You need to use a double equal sign for comparisons:
Code:
{if($1=="<user-name>") print $0}
The way you do it, the following happens: You set $1 (the first field) to user-name, the if condition is true, and you print the entire line from the password file with the new user-name.

By the way, the awk way of doing things is as follows:
Code:
$1=="username" { print }
That is, you convert the if clause to a pattern.

Last edited by berndbausch; 12-09-2015 at 08:08 AM.
 
Old 12-09-2015, 08:15 AM   #3
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
= is not the same as ==, so you are assigning a value not doing a comparison.

https://www.gnu.org/software/gawk/ma...Operators.html
 
Old 12-09-2015, 08:26 AM   #4
kamleshkk
LQ Newbie
 
Registered: Dec 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Wink

Quote:
Originally Posted by berndbausch View Post
You need to use a double equal sign for comparisons:
Code:
{if($1=="<user-name>") print $0}
The way you do it, the following happens: You set $1 (the first field) to user-name, the if condition is true, and you print the entire line from the password file with the new user-name.

By the way, the awk way of doing things is as follows:
Code:
$1=="username" { print }
That is, you convert the if clause to a pattern.
Thank you very much, sometime even simple thing never comes in mind without help
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Perl: Condition?print "Is true":print "Is false"; angel115 Programming 2 09-17-2010 06:28 AM
printing hh in hh:mm using "awk '{FS=":";print $1}'" misses first line of output!! mayankmehta83 Linux - Newbie 2 12-03-2009 02:55 AM
upgrade to kernel 2.6.16.1 : "make bzImage" print "parse error" math_physics Red Hat 2 06-29-2007 11:04 PM
how do I get around the "submit passwd" prompt in ubuntu even if I use "sudo"? t3gah Linux - Distributions 1 02-22-2005 04:42 PM
awk/gawk handling of "delete" ? realos Programming 1 06-26-2003 09:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration