cat /etc/passwd and grep -v on /etc/shells


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cat /etc/passwd and grep -v on /etc/shells
# 1  
Old 08-21-2009
cat /etc/passwd and grep -v on /etc/shells

Hi All,

I'd like to do this

cat /etc/passwd

and grep -v on the /etc/shells list

I'd like to find all shell that doesn't exist on the /etc/passwd.

Is there an easy way without doing a egrep -v "/bin/sh|/bin/bash................"?

How do I use a file /etc/shells as my list for search entries?

Thanks and more power.
# 2  
Old 08-21-2009
Code:
#!/bin/sh

for shell in $(</etc/shells)
do
  count=`grep -c $shell /etc/passwd`
  if [ $count -eq 0 ]
  then
    echo $shell not used in /etc/passwd
  fi
done

# 3  
Old 08-21-2009
To give the file as input it is -f FILENAME in grep.

But am not sure whether it fits for your requirement or not!!

Code:
grep -v -f /etc/shells /etc/passwd

# 4  
Old 08-21-2009
Try this:

Code:
awk 'NR==FNR{a[$NF];next} !($0 in a)'  FS=":" /etc/passwd FS="/" /etc/shells

# 5  
Old 08-21-2009
Oohhh, I always ignore reading all these param......

This is what I want.

grep -v -f /etc/shells /etc/passwd

Thanks to ALL!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep or cat The Whole Directory PROBLEMS :(

Hi Guys This is my first post so I am not sure how things go here. I'm sorry if I'm breaking the rule or something. Feel free to correct me about that :) So as I was saying... I'd been trying to grep this folder containing 900,000 txt files but seems no luck. I get either "No such file... (6 Replies)
Discussion started by: Nexeu
6 Replies

2. Shell Programming and Scripting

Replace cat and grep with <

Hello someone told me to use OS=`awk '{print int($3)}' < /etc/redhat-release` instead of OS=cat /etc/redhat-release | `awk '{print int($3)}'` any idea for the reason ? (5 Replies)
Discussion started by: nimafire
5 Replies

3. UNIX for Dummies Questions & Answers

Grep and cat combined

Hello, i need to search one word (snp1) from many files and copy the content of the columns of this word in new file. example: file 1: SNP BP CHR P snp1 1 3 0.01 snp2 2 2 0.05 . . file 2: SNP BP CHR P snp1 1 3 0.06 snp2 2 2 0.3 output... (6 Replies)
Discussion started by: biopsy
6 Replies

4. Shell Programming and Scripting

Directing cat or grep command in variable

Hi, I still have the problem with directing information from cat or grep to a variable. For instance: XMSG "$(date +%Y_%m_%d)_error_report.txt" "$(cat "$(date +%Y_%m_%d)_error_report.txt")" &Works! The text received by cat is directed to my function. If it is written like this, my... (2 Replies)
Discussion started by: haukee
2 Replies

5. Shell Programming and Scripting

grep or cat using sed

Is there a way using grep or cat a file to create a new file based on whether the first 9 positions of each record is less than 399999999? This is a fixed file format. (3 Replies)
Discussion started by: ski
3 Replies

6. Shell Programming and Scripting

cat -n and grep

I am not sure if using cat -n is the most efficient way to split a file into multiple files, one file per line in the source file. I thought using cat -n would make it easy to process the file because it produces an output that numbers each line that I could then grep for with the regex "^ *$i".... (3 Replies)
Discussion started by: kapu
3 Replies

7. Linux

/etc/shells on /etc/passwd

Hi All, Why does these list (below) doesn't belong to /etc/shells? sync:x:5:0:********************// :/sbin:/bin/sync shutdown:x:6:0:********************// :/sbin:/sbin/shutdown halt:x:7:0:********************// :/sbin:/sbin/halt webalizer:x:68:68:***************// ... (2 Replies)
Discussion started by: itik
2 Replies

8. UNIX for Dummies Questions & Answers

cat, grep and tee to a local file

Hi, This is what I am trying to do. 1) connect to 3 remote servers from my local machine serverA serverB serverC 2) read error file from each server cat /var/lib/mysql/mydb.err 3) grep for lines displaying "yesterday" date grep "`date +%y%m%d' '-d\"1 day ago\"`" 4) Append those lines to a... (7 Replies)
Discussion started by: shantanuo
7 Replies

9. UNIX for Advanced & Expert Users

cat and grep not working

I am trying to cat a file and then grep that file for a number. I can do it fine on other files but this particular file will not do anything. I tried running it on an older file from the same device but it is just not working. The file is nothing more than a flat file on a unix box. Here is just a... (3 Replies)
Discussion started by: jphess
3 Replies

10. UNIX for Dummies Questions & Answers

grep group and passwd file

How can I find find all members in the /etc/password file that belong to the dba group in the /etc/group file? (4 Replies)
Discussion started by: mozartny
4 Replies
Login or Register to Ask a Question