Computing.Net > Forums > Unix > wildcards searching loopq

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

wildcards searching loopq

Reply to Message Icon

Name: abhargav
Date: May 18, 2005 at 06:58:02 Pacific
OS: linux
CPU/Ram: 256 SDRAM
Comment:

hi
i have a question for using searching in /etc/shadow with wildcard.it just struct to my mind but i cudnt get hold of it.if any of the linux gurus can help me out.help will be duly appreciated.

my /etc/shadow file is

vscan:!:12775:0:99999:7:::
man:*:8902:0:10000::::
man:!:12775:0:99999:7:::
man:!:12775:0:99999:7:::
news:*:8902:0:10000::::
news:!:12775:0:99999:7:::
news:!:12775:0:99999:7:::
man:*:8902:0:10000::::
man:!:12775:0:99999:7:::
man:!:12775:0:99999:7:::
baz:$2a$05QeMyohjS9cDVtYwKTU7LacuaJ7ySc2oDQRBnxCWhrHMbceYZ9urZci:12795:0:99999:7:::
abhishek:$2asaasajajsasajsjansjnajnaj:12323:0:2323:2:::
abhi:@32323232323232:12902:14:93:7:30::

now i want to search using wildcards.So if i take user input as ab* it should give me abhishek and abhi .
now i hav used this.

for WHO in `$AWK -F":" '{print $1}' $SHADOW` ; do

if [ "$WHO" = "$var" ] ; then
echo "usr found"
else
echo "usr not found"

fi
done

can anyone help me out.i mean how do i search with wildcard * .they seems to be having unpredicatble behaviour

hi
my question is abt scripting.
i want to find the diffrence in two dates.
dates are in /var/log/messages

Mar 27 05:48:02 abhargav sshd[1151]:
Apr 2 15:31:17 abhargav sshd[1151]:

no



Sponsored Link
Ads by Google

Response Number 1
Name: cdac1000
Date: May 18, 2005 at 07:50:45 Pacific
Reply:

Hi,

I dont quite get the idea of searching a userid in /etc/shadow as a normal user you wont have access on this file. Also if you just want to check the username why not use /etc/passwd??

Anyway have a look at the following script, may hold the key to your problem.

#!/bin/bash
for WHO in `awk -F":" '{print $1}' /etc/passwd | grep "^$1"`
do
echo $WHO
done

print only the user id's from /etc/passwd and use grep to do wild card search with $1 passed from command line as parameter to the script. I put it as grep "^$1" meaning beginging of the word.

Hope this helps.


0

Response Number 2
Name: David Perry
Date: May 18, 2005 at 08:02:50 Pacific
Reply:

#!/bin/ksh
if [ $# -eq 0 ] ; then
echo "USAGE $0 pattern"
exit 4
fi
PATTERN=$1
for who in `awk -F: '{ print $1 }' /etc/shadow` ; do
if [ `echo $who | grep -c --regex="$PATTERN"` -gt 0 ] ; then
echo "User $who found"
fi
done


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: wildcards searching loopq

Help: how do i search a file? www.computing.net/answers/unix/help-how-do-i-search-a-file/4660.html

Searching for more then one word www.computing.net/answers/unix/searching-for-more-then-one-word/5027.html

Search function www.computing.net/answers/unix/search-function-/2321.html