The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File filter Dastard Shell Programming and Scripting 3 09-06-2007 10:50 AM
Filter using awk arun_st UNIX for Dummies Questions & Answers 3 03-21-2007 04:20 AM
Mail Filter collins UNIX for Advanced & Expert Users 4 11-16-2004 02:46 AM
ftp by date filter campbem UNIX for Dummies Questions & Answers 1 02-11-2004 10:44 AM
spam filter fnoyan High Level Programming 2 11-16-2003 06:10 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-03-2005
Registered User
 

Join Date: Jan 2005
Posts: 5
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-03-2005
Registered User
 

Join Date: Dec 2000
Location: Greater Dallas area
Posts: 405
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*:
__________________
[url=http://chuckb.1le.net/]My website[/url]
Reply With Quote
  #3 (permalink)  
Old 01-03-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,226
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
Reply With Quote
  #4 (permalink)  
Old 01-03-2005
Registered User
 

Join Date: Jan 2005
Posts: 5
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 12:24 AM.
Reply With Quote
  #5 (permalink)  
Old 01-04-2005
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
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:....
$
Reply With Quote
  #6 (permalink)  
Old 01-04-2005
Registered User
 

Join Date: Jan 2005
Posts: 5
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
Reply With Quote
  #7 (permalink)  
Old 01-04-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,354
Hmmm...I guess Ygor had a typo...

awk -F: '$2 !~ "\*"' file
Reply With Quote
Google UNIX.COM
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0