Filter passwd


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter passwd
# 1  
Old 01-03-2005
Filter passwd

Hello,
I have to build a temp. passwd-file without looked passwd entries in the /etc/passwd.

The looked passwd fields have an "*" in the passwd-filed (2nd field).

I think, it's possible to solve this problem with a small awk, but I don't know how ???

Normal users lines should be still in the new file, all lines with the following example "*" in the second field should be filtered, like:

otto:***LOCKED***:....
Mueller:*:....
Klaus:*TTT*:

What is the syntax (in awk) ?


Thx,
Martin
# 2  
Old 01-03-2005
The easy way would be:
Code:
 grep -v \*\*\* /etc/passwd > temp.passwd

The awk way would be:
Code:
 awk '! /\*\*\*/' /etc/passwd > temp.passwd

I assume this is what you are looking for:
Code:
-bash-2.05b$ cat t
otto:***LOCKED***:....
Mueller:*:....
Klaus:*TTT*:
-bash-2.05b$ awk '! /\*\*\*/' t
Mueller:*:....
Klaus:*TTT*:

# 3  
Old 01-04-2005
Depending on what you want.

To list lines where the second field is "*"...
awk -F: '$2 == "*"' file1

To list lines where the second field contains "*"...
awk -F: '$2 ~ "*"' file1

To list lines where the second field is not "*"...
awk -F: '$2 != "*"' file1

To list lines where the second field does not contain "*"...
awk -F: '$2 !~ "*"' file1
# 4  
Old 01-04-2005
Sorry,
maybe my wish was not so clear.

I want to see in the new file all entries without the lines which contain characters like "*", "***LOCKED***", *XX*", ... in the second field.

I know, how to create to filter for specially (f.e.) "***LOCKED***", but what will be the syntax to filter different combinations with "*" in the second field (the filter should only check the entrie in the second field (ANYTHING:CHECK-THIS:ANYTHING:ANYTHING:.......)

Input:
otto:***LOCKED***:....
Sven:7hfd7ihd7fd:....
Mueller:*:....
Tanja:ukjs7i437jd:....
Klaus:*TTT*:

Output:
Sven:7hfd7ihd7fd:....
Tanja:ukjs7i437jd:....

Regards,
Martin

Last edited by Topsurfer; 01-04-2005 at 04:24 AM..
# 5  
Old 01-04-2005
Is this what u are looking for ????

$ cat file1
otto:***LOCKED***:....
Sven:7hfd7ihd7fd:....
Mueller:*:....
Tanja:ukjs7i437jd:....
Klaus:*TTT*:
$ grep -v "*" file1
Sven:7hfd7ihd7fd:....
Tanja:ukjs7i437jd:....
$
# 6  
Old 01-04-2005
No,
the filter should only "see" * in the second field,
your grep find every * everywhere in the line !

I know "grep -v" etc., but not shurte how the syntax is for awk -??? -NF=2 [?*?] or so ?????

Example:
Input:
otto:***LOCKED***:Comment 123:
Sven:7hfd7ihd7fd:Comment ***! :
Mueller:*:....:No Comment
Tanja:ukjs7i437jd:No Asterix here:
Klaus:*TTT*:*Comment*

Output:
Tanja:ukjs7i437jd:....
Sven:7hfd7ihd7fd:Comment ***! :

(also Sven, because the "*" is in NOT in the second field !!


Martin
# 7  
Old 01-04-2005
Hmmm...I guess Ygor had a typo...

awk -F: '$2 !~ "\*"' file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

2. AIX

When did AIX start using /etc/security/passwd instead of /etc/passwd to store encrypted passwords?

Does anyone know when AIX started using /etc/security/passwd instead of /etc/passwd to store encrypted passwords? (1 Reply)
Discussion started by: Anne Neville
1 Replies

3. UNIX for Dummies Questions & Answers

etc/passwd help

Hi! i've been searching a way to display the users who are in the /etc/passwd directory...using ls or grep or cat command should do it?i can't find a way to get this right..i mean none of the preview commands function sounded good to me to use... (9 Replies)
Discussion started by: strawhatluffy
9 Replies

4. UNIX for Dummies Questions & Answers

passwd

Hello , how to open utemp,getpwuid files.I know what info these files will carry but i dont know ow to open see the info present in it. Thanks to help. (4 Replies)
Discussion started by: kkalyan
4 Replies

5. Solaris

passwd cmd reenables passwd aging in shadow entry

Hi Folks, I have Solaris 10, latest release. We have passwd aging set in /etc/defalut/passwd. I have an account that passwd should never expire. Acheived by emptying associated users shadow file entries for passwd aging. When I reset the users passwd using passwd command, it re enables... (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies

6. Shell Programming and Scripting

/etc/passwd

Hello All I want to print only the full name from the /etc/passwd file and print it to the screen . Could you please let me know how can I do that? (4 Replies)
Discussion started by: supercops
4 Replies

7. UNIX for Dummies Questions & Answers

etc/passwd

Can anyone explain the second and third fields in /etc/passwd. Thanks. (2 Replies)
Discussion started by: nguda
2 Replies

8. UNIX for Dummies Questions & Answers

passwd

hello, I don't why I can't change the password, when ever I try to run passwd I get the problem??!!! unixws1:ldb> passwd passwd: Changing password for ldb Permission denied regards, me (2 Replies)
Discussion started by: geoquest
2 Replies

9. UNIX for Advanced & Expert Users

passwd

I have to change more then 200 User at once the password (security-dday). The programm passwd will answers (new password + again) How can i do this in a script? thanks for answers (5 Replies)
Discussion started by: Erwin Stocker
5 Replies

10. UNIX for Advanced & Expert Users

passwd

Hi, Besides of the command "passwd" on Solaris and HP-UX and IRIX that allow users to change their passwords on the system. Is there anyother way a user can change his/her own password. Do any of these systems have a GUI interface to allow the user doing so? Thanks (3 Replies)
Discussion started by: vtran4270
3 Replies
Login or Register to Ask a Question