![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
The easy way would be:
Code:
grep -v \*\*\* /etc/passwd > temp.passwd Code:
awk '! /\*\*\*/' /etc/passwd > temp.passwd 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] |
|
|||
|
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. |
|
|||
|
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 |