AWK? parsing /etc/passwd file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK? parsing /etc/passwd file.
# 1  
Old 03-02-2012
Hammer & Screwdriver AWK? parsing /etc/passwd file.

Hello guys,
please help me to make simple script for parsing passwd file.
I have many passwd files from our servers, named server1.pass, server2.pass etc..
so
for server in `ls *.pass`
i need to print these rows:

server1;root:!:0:0::/root:/usr/bin/ksh
server1;user1:!:10166:10010:Admin:/home/user1:/bin/ksh
server1;user2:!:10167:10010:Admin:/home/user1:/bin/ksh
server2;user1:!:10168:10010:Admin:/home/user1:/bin/ksh
server2;user2:!:10169:10010:Admin:/home/user1:/bin/ksh
etc..
in one accounts.csv file
i have to skip all system accounts ( guess < 50 uid) but i need root account included.

Thank you very much for your help and have a nice day!!
Lukas Smilie
# 2  
Old 03-02-2012
Code:
# awk -F: '$3>100&&$0!~/nologin/{gsub("\\..*|/.*/","",FILENAME);print FILENAME";"$0}' server?.pass > accounts.csv

if there are a lot of inputs then u can change input name as like `server[0-9]*.pass`
This User Gave Thanks to ygemici For This Post:
# 3  
Old 03-02-2012
Quote:
Originally Posted by ygemici
Code:
# awk -F: '$3>100&&$0!~/nologin/{gsub("\\..*|/.*/","",FILENAME);print FILENAME";"$0}' server?.pass > accounts.csv

if there are a lot of inputs then u can change input name as like `server[0-9]*.pass`
thank you but:
awk: syntax error near line 1
awk: illegal statement near line 1
Smilie
# 4  
Old 03-02-2012
what is your os and awk v ?

---------- Post updated at 03:19 PM ---------- Previous update was at 02:49 PM ----------

try this Smilie
Code:
# /usr/xpg4/bin/awk -F':' '$3>100&&$0!~/nologin/||$3==0{gsub("\\..*|/.*/","",FILENAME);print FILENAME";"$0}' server[0-9]*.pass

regards
ygemici
This User Gave Thanks to ygemici For This Post:
# 5  
Old 03-02-2012
Quote:
Originally Posted by ygemici
what is your os and awk v ?

---------- Post updated at 03:19 PM ---------- Previous update was at 02:49 PM ----------

try this Smilie
Code:
# /usr/xpg4/bin/awk -F':' '$3>100&&$0!~/nologin/||$3==0{gsub("\\..*|/.*/","",FILENAME);print FILENAME";"$0}' server[0-9]*.pass

regards
ygemici

works like a charm thanks
# 6  
Old 03-05-2012
Hammer & Screwdriver more option

Can i have more question to this issue please?

i modified your script to this:
/usr/xpg4/bin/awk -F':' '$3>100&&$1!~/nobody/||$3==0{gsub("\\..*|/.*/","",FILENAME);print FILENAME";"$0}' *.pass > userreport.csv

i want to keep accounts with nologin, but i want to skip some exact accounts like "nobody". How can i add more users that i want to discard.
So for example, output will be users with uid>100,uid=0, but except users (nobody,sshd and snmp).

Thank you ver ymuch for another help and have a nice day.
Lukas Smilie
# 7  
Old 03-05-2012
Quote:
Originally Posted by rubico
Can i have more question to this issue please?

i modified your script to this:
/usr/xpg4/bin/awk -F':' '$3>100&&$1!~/nobody/||$3==0{gsub("\\..*|/.*/","",FILENAME);print FILENAME";"$0}' *.pass > userreport.csv

i want to keep accounts with nologin, but i want to skip some exact accounts like "nobody". How can i add more users that i want to discard.
So for example, output will be users with uid>100,uid=0, but except users (nobody,sshd and snmp).

Thank you ver ymuch for another help and have a nice day.
Lukas Smilie
you can try this Smilie
Code:
# /usr/xpg4/bin/awk -F':' '$3>100&&$1!~/nobody|sshd|snmp/||$3==0{gsub("\\..*|/.*/","",FILENAME);print FILENAME";"$0}' *.pass > userreport.csv

regards
ygemici
This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a file name with awk

I have a command to print out the top 5 most cpu intensive commands: ps aux --sort=-%cpu --no-headers I would like to make a printout containing only the parsed file name. So, I want to turn this: $ ps aux --sort=-%cpu --no-headers user 24883 4.3 1.7 2010436 131440 ? Sl ... (2 Replies)
Discussion started by: bedtime
2 Replies

2. Shell Programming and Scripting

awk parsing file

Looking to parse a file to remove the duplicates and get only few fields and uniq rows. input.tx Loc (TC) ID : ssfad_fs Serial : PIC002340098 ... (8 Replies)
Discussion started by: shunya
8 Replies

3. Shell Programming and Scripting

awk - printing the passwd file

I've got a number of RHEL systems and I'm trying to use awk to read and format the output of /etc/passwd. But I'd like to display the host name of the system at the beginning of each line of output. I've got it working without the adding the host name in this script: #!/bin/bash ... (3 Replies)
Discussion started by: westmoreland
3 Replies

4. Shell Programming and Scripting

Help in file parsing with awk

Hi, I have a data set as shown below: 09e757fd,22727,2012-03-01,text1,text2,to 3fd0cae7,310,2012-03-01,text3,text4,to 3fd0cae7,310,2012-03-01,text3,text5,to 3fd0cae7,311,2012-03-01,text7,text10,cc 3fd0cae7,311,2012-03-01,text7,text11,to 3fd0cae7,312,2012-03-01,text8,text15,to... (3 Replies)
Discussion started by: shekhar2010us
3 Replies

5. UNIX for Dummies Questions & Answers

parsing /etc/passwd

i am parsing te /etc/passwd file and extracting the login and names alone. But for some entries only login exist but no name. so i dont want to display those: how i can check non emptiness for login and name in single if statement: #!/usr/bin/bash while IFS=: read login a b c name e do ... (3 Replies)
Discussion started by: pandeesh
3 Replies

6. Shell Programming and Scripting

awk parsing of ICS file

Hi, I am searching for a fast awk hack to eliminate from an ICS file events which have been modified at a certain time. The structure for parsing is the following: BEGIN:VEVENT .... LAST-MODIFIED:...some date... ... END:VEVENT If the date matches for example LAST-MODIFIED:20110823 the... (2 Replies)
Discussion started by: mmtung
2 Replies

7. Shell Programming and Scripting

Parsing a file with AWK

Input Group: Erecords: Copy: ADC R2: Replication volumes: Replication set: RSet 1 Replication size: 50.00GB SAN Info: 50.00GB DGC VRAID CX4-960 LUN 1040 (1040) 60,06,01,60,32,bb,21,00,84,a0,08,b1,da,ec,df,11... (2 Replies)
Discussion started by: greycells
2 Replies

8. UNIX for Advanced & Expert Users

Parsing through a file with awk/sed

I don't necessary have a problem, as I have a solution. It is just that there may be a better solution. GOAL: Part one: Parse data from a file using the "\" as a delimiter and extracting only the last delimiter. Part two: Parse same file and extract everything but the last delimited item. ... (8 Replies)
Discussion started by: OrangeYaGlad
8 Replies

9. Shell Programming and Scripting

awk and file parsing

Hi, I have a input file like this TH2TH2867Y NOW33332106Yo You Baby TH2TH3867Y NOW33332106No Way Out TH2TH9867Y NOW33332106Can't find it TJ2TJ2872N WOW33332017sure thing alas TJ2TJ3872N WOW33332017the sky rocks TJ2TJ4872N WOW33332017nothing else matters ... (4 Replies)
Discussion started by: devtakh
4 Replies

10. Shell Programming and Scripting

parsing file through awk

hi, how can i achieve this in awk CON Controllers Department R abcuser usernamedesc1 R defuser usernamedesc2 R ... (13 Replies)
Discussion started by: bbeugie
13 Replies
Login or Register to Ask a Question