LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-07-2014, 06:04 AM   #1
kbcarn
LQ Newbie
 
Registered: Feb 2014
Posts: 1

Rep: Reputation: Disabled
awk help


Hi All,

Code:
awk -F':' '/\/home.*sh/ { print $1 }' /etc/passwd
The above command can print all users who are having login shell either /bin/sh or /bin/bash with their home directory whichever starts from /home. The same way I wanted to print those users also whose home directories starts from /data. So expecting your kind help for the same in a single awk command.

Last edited by kbcarn; 02-11-2014 at 09:41 AM.
 
Old 02-07-2014, 06:22 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,617

Rep: Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088Reputation: 2088
Rather than "expecting" others to do it for you, how about you show us what you attempted ?.
 
1 members found this post helpful.
Old 02-07-2014, 06:22 AM   #3
mandyapenguin
Member
 
Registered: Nov 2011
Location: India
Distribution: RedHat, Cent OS, Fedora, Debian, Ubuntu
Posts: 106

Rep: Reputation: Disabled
I am not an expert in awk but "pipe" worked for me.
Code:
awk -F':' '/\/home|data.*sh/ { print $1 }' /etc/passwd

Last edited by mandyapenguin; 02-07-2014 at 06:30 AM. Reason: modify
 
Old 02-07-2014, 08:31 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,504

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
@mandyapenguin - you may need to rethink the logic of your regex:

/\/home|data.*sh/ - - Either the line contains '/home' or 'data' followed by any characters ending in 'sh'

So using the above logic, if your users login name happened to be datash the print command will be invoked

As for the OP, I am with syg00 that you need to show your attempt and where it is not working if you wish anyone to assist.
 
1 members found this post helpful.
Old 02-07-2014, 10:04 AM   #5
mandyapenguin
Member
 
Registered: Nov 2011
Location: India
Distribution: RedHat, Cent OS, Fedora, Debian, Ubuntu
Posts: 106

Rep: Reputation: Disabled
Unhappy

Yes Guru, you are right. I had tested it with Cent O/S by creating one more user called "testing" and its home directory as "/data/testing", that time it gave me the expected output. But when I tried the same from Ubuntu, got the usernames like www-data, syslog and even more which are not even expected!
Sorry for the same. If you are ok, now I am also with syg00

Last edited by mandyapenguin; 02-07-2014 at 10:22 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How do I list 'WORDS' containing a specific character? awk,sed,grep? rohit.dhaval1 Linux - Newbie 10 08-22-2012 09:08 AM
[SOLVED] awk - sort words within each line danielbmartin Programming 3 02-03-2012 11:17 AM
[SOLVED] Awk - finding and counting words specific letters within mora978 Programming 9 10-13-2010 10:45 AM
Get all lines containing 23 specific words with AWK cgcamal Programming 3 11-05-2008 10:51 AM
grep/sed/awk - find match, then match on next line gctaylor1 Programming 3 07-11-2007 08:55 AM


All times are GMT -5. The time now is 02:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration