Grep - Searching for multiple items using one command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep - Searching for multiple items using one command
# 1  
Old 02-26-2013
Grep - Searching for multiple items using one command

I am performing a regular check on UNIX servers which involves logging onto UNIX servers and using the grep command to check if a GID exists in the /etc/group directory

e.g. grep 12345 /etc/group

I have five to check on each server, is there anyway I can incorporate them into one command and get an output if the group exists.

e.g. The GIDs are 12345 54321 56789 98765 12986
# 2  
Old 02-26-2013
Quote:
Originally Posted by @MeDaveT
I am performing a regular check on UNIX servers which involves logging onto UNIX servers and using the grep command to check if a GID exists in the /etc/group directory

e.g. grep 12345 /etc/group

I have five to check on each server, is there anyway I can incorporate them into one command and get an output if the group exists.

e.g. The GIDs are 12345 54321 56789 98765 12986
Try:
Code:
grep -E '12345|54321|56789|98765|12986' /etc/group

# 3  
Old 02-27-2013
More precise is
Code:
egrep ':(12345|54321|56789|98765|12986):' /etc/group

Most precise is
Code:
awk -F: '$3~/^(12345|54321|56789|98765|12986)$/' /etc/group

Last but not least let me advertise getent:
Code:
getent group 12345 54321 56789 98765 12986

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with search and replacing multiple items in multiple files

Im having an issue when trying to replace the first column with a new set of values in multiple files. The results from the following code only replaces the files with the last set of values in val.txt. I want to replace all the files with all the values. for date in {1..31} do for val in... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

2. Shell Programming and Scripting

Searching for multiple patters using grep

i have a file as below grepfile.txt ---------------- RNTO command successful No such file or directory Authentication failed if i seach individually for 'RNTO command successful' or 'No such file or directory' using grep -i as below, im gettting result. grep -i 'No such file or... (5 Replies)
Discussion started by: JSKOBS
5 Replies

3. UNIX for Dummies Questions & Answers

Grep in Perl - Searching through multiple files

I'm attempting to use grep in Perl with very little success. What I would like to do in Perl is get the output of the following grep code: grep -l 'pattern' * This gives me a list of all the files in a directory that contain the pattern that was searched. My attempts to do this in Perl... (4 Replies)
Discussion started by: WongSifu
4 Replies

4. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

5. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

6. Shell Programming and Scripting

Full text searching for multiple items

I am trying to find a solution to a request here at work. I have been asked to do a full text search of around 300,000 files for multiple content items. The following words need to appear in the file. (april and\or may) and pie and (red and\or white). So a file with the words april... (6 Replies)
Discussion started by: kondoor
6 Replies

7. UNIX for Dummies Questions & Answers

Searching multiple items

Hi, I'm a complete newbie so bear with me. I have a directory (and sub-dirs) full of .doc, .xls files. What I'm trying to do is do a single search within the files (i.e. within each .doc etc) for occurrences of multiple items e.g. apples, pears, grapes, bananas. Basically I'd provide a... (4 Replies)
Discussion started by: kainfs
4 Replies

8. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

9. Shell Programming and Scripting

searching using grep command

Hi, i have a file called alert_pindb.log i need to grep and count for all the lines starting with "ORA-" but i need to exclude the line which is having "ORA-00600 " i am using following syntax to count the ORA- nos "grep \"ORA-\" alert_pindb.log | wc -l"; since ORA- may be anything... (9 Replies)
Discussion started by: prakash.gr
9 Replies

10. UNIX for Dummies Questions & Answers

Searching mutiple word - Tuning grep command

Hi all, I have a log file which is more than 1GB, i need to take count from the log file for two strings. i am using the below command but it take a long time to excetue, i need to tune this. Please help me cat /logs/gcbs/gcbsTrace.log | grep -i "ViewStatementBusinessLogic" | grep -c -i... (8 Replies)
Discussion started by: senthilkumar_ak
8 Replies
Login or Register to Ask a Question