Organizing text file by Capital Names (capital word ' ' capital word)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Organizing text file by Capital Names (capital word ' ' capital word)
# 1  
Old 02-24-2015
Wrench Organizing text file by Capital Names (capital word ' ' capital word)

Hi I have a file passwd_exmpl that contains:

Code:
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
unbound:x:998:997:Unbound DNS resolver:/etc/unbound:/sbin/nologin
colord:x:997:996:User for colord:/var/lib/colord:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
saslauth:x:996:76:"Saslauthd user":/run/saslauthd:/sbin/nologin
libstoragemgmt:x:995:994:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
chrony:x:994:993::/var/lib/chrony:/sbin/nologin
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:993:991::/run/gnome-initial-setup/:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
acctmgr:x:1000:1000:acctmgr:/home/acctmgr:/bin/bash

and I am tasked with getting the first and fifth field which I did here
Code:
cut -f 1,5 -d ':' --output-delimiter=' '  passwd_exmpl

which then outputs

Code:
root root
bin bin
daemon daemon
adm adm
lp lp
sync sync
shutdown shutdown
halt halt
mail mail
operator operator
games games
ftp FTP User
nobody Nobody
dbus System message bus
polkitd User for polkitd
unbound Unbound DNS resolver
colord User for colord
usbmuxd usbmuxd user
saslauth "Saslauthd user"
libstoragemgmt daemon account for libstoragemgmt
avahi Avahi mDNS/DNS-SD Stack
qemu qemu user
avahi-autoipd Avahi IPv4LL Stack
rpc Rpcbind Daemon
rpcuser RPC Service User
nfsnobody Anonymous NFS User
rtkit RealtimeKit
ntp 
chrony 
mysql MariaDB Server
radvd radvd user
abrt 
pulse PulseAudio System Daemon
gdm 
gnome-initial-setup 
postfix 
sshd Privilege-separated SSH
tcpdump 
acctmgr acctmgr

I need to just have the usernames and full names while excluding any of the roots and garbage I don't need and can't figure out how to go about this... Any help would be greatly appreciated, Thanks.

Last edited by Don Cragun; 02-22-2016 at 03:49 AM.. Reason: Scrub user accounts.
# 2  
Old 02-24-2015
not sure what you mean by 'grabage', but here's something to start with:
Code:
awk -F: '!/(root|garbageGoesHere)/ && $5 {print $1,$5}' passwd_exmpl

# 3  
Old 02-24-2015
Thanks for replying, but I need to only include names in the fifth field so I'm thinking if I could just grab the lines if the fifth field is in line with "capital first name" space "capital last name" then output only those lines so it wouldn't print something like "mail mail" or "games games" but instead lines like "wallack Phil Wallack" or "clocke1 Chris Locke" etc.
# 4  
Old 02-24-2015
ok, how about:
Code:
awk -F: '$5~/^[A-Z].* [A-Z]/ {print $1,$5}' passwd_exmpl

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 02-24-2015
Ok thanks your code worked I added a tail pipe to get exactly what I wantedSmilie

Code:
awk -F: '$5~/^[A-Z].*[A-Z]/ {print $1,$5}' passwd_exmpl|tail -58

# 6  
Old 02-25-2015
If "garbage" is root and other system accounts, and you are interested only in "normal" users, you might want to check for the uid ($3) to be >= 1000. The UID_MIN value if found in e.g. /etc/login.defs on linux system.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

changing all characters of a file to capital letters

Hi guys. I have file named output.txt containing file names. one per line. I use this command to convert all characters to capital letters and write to the same file. cat output.txt | tr 'a-z' 'A-Z' > output.txtBut at the end output.txt is emtpy. Could anyone help?? (6 Replies)
Discussion started by: majid.merkava
6 Replies

2. Shell Programming and Scripting

converting day to capital letter...

Hello, I am receiving a file every day as this format. Since today is friday, the format is, PGI_STG_FRIDAY14.TXT. I need to write the shell script to check if this file exist in folder... I am using date format.. export DATE=`date '+%A'` echo $DATE The output is Friday But i... (8 Replies)
Discussion started by: govindts
8 Replies

3. UNIX for Dummies Questions & Answers

How to search for capital letters

Hi, I just want to search a file for any words containng a capital letter and then display a list of just these words! I have been trying grep but to no has not helped.(im using the bash shell) (1 Reply)
Discussion started by: djdaniel3
1 Replies

4. Shell Programming and Scripting

how to find capital letter names in a file without finding words at start of sentence

Hi, I want to be able to list all the names in a file which begin with a capital letter, but I don't want it to list words that begin a new sentence. Is there any way round this? Thanks for your help. (1 Reply)
Discussion started by: kev269
1 Replies

5. Shell Programming and Scripting

Change a parameter to be in capital letters

Hi, I have a korn shell script with 1 parameter. My script deletes certain files, for example.... sid=$1 rm $ORC/dbs/orapwd${sid} #orapwddb1 rm $ORC/dbs/lk${sid} #lkDB1 In the first file, the $sid must be in small letters and in the second file, the $sid must be in capital... (4 Replies)
Discussion started by: n8575
4 Replies

6. Shell Programming and Scripting

capital sed

Hi everyone. I wanted to convert capital characters to small one. So i tried to use: sed -e "y///" but this won't work. And sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" this worked well. Does anyone know why?? (2 Replies)
Discussion started by: Euler04
2 Replies

7. UNIX for Dummies Questions & Answers

capital letters GONE!

I have an odd issue. I am trying to copy some files/folders to my linux box via a burned CD which I created on my mac. When I browse the files on the mac (or my windows box), everything looks fine (some of the folder names start with a capital letter, which is needed for everything to work... (8 Replies)
Discussion started by: blogg
8 Replies

8. UNIX for Dummies Questions & Answers

Transformation capital letter

:confused: Hye everybody i would like to know if exist a internet site where i can founs some interesting shell script very usefull I need to transform hundreds names of files escribed in CAPITAL letter in minuscule letter do oyu know a mean o do that that thanks to a script or a shell... (1 Reply)
Discussion started by: Dark Angel
1 Replies
Login or Register to Ask a Question