searching apattern...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers searching apattern...
# 1  
Old 08-04-2008
searching apattern...

I need to write a shell script which accepts list of users which can be passed as parameters and also taken from a file.. and need to find weather all users are valid users or not..( check in /etc/passwd)

i wrote..like this..

if [ -z $@ ]
then echo enter file name...
read file
grep -f $file /etc/passwd && echo user valid || echo user invalid
exit
else
grep "$@\>" /etc/passwd && echo user valid || echo user invalid
fi
exit

but it worked fine if user name passed tru command line arguments but not worked while taking from a file

example if user33 is a valid user but user3 is not but if v search for unix3(taken from a file) it shows valid user...

if anyone understood this pleasee help me.....
# 2  
Old 08-04-2008
Use -w option with grep while searching for user.
It will force pattern to match complete word. Smilie

Here as grep is searching pattern for user3 which comes in user33, so it is matching there.

- nilesh
# 3  
Old 08-04-2008
use awk to match the user name
awk -F':' '$1 == "$variablename"' /etc/passwd

with the other problem, you are making tons of mistakes, but not even checking how many parameters you have

Advanced Bash-Scripting Guide

you need to chek that,

and if you need to read names form a file, use something like

while read line
do
echo "the var line contains this: $line"
done < /path/to/file
# 4  
Old 08-04-2008
tanq very much

i am very much new to unix tanx for ur response
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

2. UNIX for Dummies Questions & Answers

Searching

Hi guys, I have a very common issue :( im trying to work it out but I am still not used to it. my problem is searching. very often I should look for piece of string in a text file or a file itself: I want to learn some easy and professional commands to ease this routine for me. I want to be... (2 Replies)
Discussion started by: messi777
2 Replies

3. Shell Programming and Scripting

grep searching

I am making a script but having little problem. at one part I need to find one number format or other format from a file.. those formats are xxx-xx-xxxx or xxxxxxxxx i tried grep '( \{3\}-\{2\}-\{3\} |\{9\})' if i do them sepratly it work but like this it is not working Please check... (7 Replies)
Discussion started by: Learnerabc
7 Replies

4. UNIX for Dummies Questions & Answers

searching

How would i search to find all the lines consisting of of only the letter "z" followed by any four characters? (1 Reply)
Discussion started by: trob
1 Replies

5. Shell Programming and Scripting

file searching...

Hi! i'm trying to do a script (i'm not an expert, as you will see...:o) to search files in a directory (and its subdirectories). I'd like to have something like this: mysearch -a arg1 -b arg2 -c arg3 ecc... I'd like to be able to search for files in different ways: for example, with my... (1 Reply)
Discussion started by: Kaminski
1 Replies

6. UNIX for Dummies Questions & Answers

Searching in VI

Hi, I would like to do a search and replace on a file using vi. Something like this: :%s/dst_port=****//g I want to search the entire file and replace all text that does not match dst_port=**** with space or nothing. In other words delete everything except for dst_port=****. The four *... (1 Reply)
Discussion started by: andyblaylock
1 Replies

7. Shell Programming and Scripting

searching a file

Hi At the moment I am able to add text to a file but what I need to do is make sure the same value is not duplicated. Can anyone tell me how to search a file and prevent an update from taking place if the value to be entered already exists in the file? Any help would be greatly... (4 Replies)
Discussion started by: straight_edge
4 Replies

8. UNIX for Advanced & Expert Users

Searching Files

Hi, I have a file /db01/dat/march 2006/7001DW06.03B Please note, between "march 2006" there is a space/tab. While running the following script, it identifies /db01/dat/march ----> as first file 2006/7001DW06.03B ---> as second file. SRC_PATH = /db01/dat SEARCH_FILENAME =... (12 Replies)
Discussion started by: ronald_brayan
12 Replies

9. Shell Programming and Scripting

searching searching

Guys Im checking some of my files for errors. I want to be able to find text and make sure it's located on the right place. Example Chapter 1 TEXT LKJ TEXT 12Y more and more text Chapter 2 TEXT 34G TEXT HHG more and more text Chapter 3 TEXT FG45 TEXT 11w more and more text ... (3 Replies)
Discussion started by: tony3101
3 Replies

10. Shell Programming and Scripting

searching for {

Hello, I am having a hard time trying to do the following: I have a file that looks like this: 0 CacheMaxConn 4 64 0 RMThread 16 3423423 7 DataSource 0 /hello/sas/ses 0 {94545B4-E343-1410-81E4-08000000} 3 DDBE 3 ... (4 Replies)
Discussion started by: yotoruja
4 Replies
Login or Register to Ask a Question