Sponsored Content
Top Forums Shell Programming and Scripting how to use sed to sort out this question Post 302182573 by sonicstage on Monday 7th of April 2008 03:29:12 AM
Old 04-07-2008
how to use sed to sort out this question

root:x:0:0:0000-Admin(0000):/:/sbin/sh
rootcsh:x:0:1:0000-Admin(0000):/:/bin/csh
nocol:x:6312:630:NOCOL Monitor,,,:/usr/local/lib/nocol-client:/usr/local/bin/bash
nobody:x:60001:60001:uid no body:/:/usr/local/bin/bash
noaccess:x:60002:60002:uid no access:/:/usr/local/bin/bash
nobody4:x:65534:65534:SunOS 4.x NFS Anonymous Access User:/:/usr/local/bin/bash
+@c_staff::::::
+::::::/usr/local/sbin/nologin

all above content are in a file called passwd.txt
username:password:uid:gid:gcos-field:home-dir:login-shell
(i)write a shell script and make above output the fields:username,shell,home directory
(ii)and also removes all the lines which start with a '+'

Last edited by sonicstage; 04-07-2008 at 04:43 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sort Question

M 47 HIS:LOT 32 DUTY 2 MIKE, FINISHED MIKE ACTIVE STATUS 23TASK YES GOOD 100TASK NO GOOD ======================================== M 47 HIS:LOT 1 DUTY 1 MIKE, FINISHED MIKE ACTIVE STATUS 23TASK YES GOOD ... (7 Replies)
Discussion started by: bobo
7 Replies

2. UNIX for Dummies Questions & Answers

Sort/Grep Question

Hello all, I have a test file that has the format: ..... O 3.694950 -.895050 1.480000 O 5.485050 .895050 1.480000 Ti -4.590000 4.590000 2.960000 Ti -2.295000 ... (5 Replies)
Discussion started by: aarondesk
5 Replies

3. UNIX for Dummies Questions & Answers

SORT question

I'm looking for a sort command that will sort by zip code first then by last name. (zip code is the last field, last name is first field) data file looks like this. Hope Bob 1234 Main ST. Colorado Springs, CO 80920 I was thinking along the lines of: sort -k9n address.data //for the... (2 Replies)
Discussion started by: ssgatbliss
2 Replies

4. Shell Programming and Scripting

sort / cut question

Hi All, I have a small problem, hope you can help me out here. I have a file that contains the same format of lines in 99% of the cases. 906516 XYZ.NNN V 0000 20070711164648 userID1 userID2 hostname 20070711164641 There are unfortunately several lines with these... (5 Replies)
Discussion started by: BearCheese
5 Replies

5. Shell Programming and Scripting

sort question

Hi all. Is there a way that I can use the sort command too sort the following field by earliest time (12:00AM) to latest time (11:59PM)? 07:12PM 07:53PM 07:54PM 08:07PM 10:15AM 10:21AM TIA!!!!!! (1 Reply)
Discussion started by: lyoncc
1 Replies

6. Shell Programming and Scripting

sort question

Hi all. HPUX - posix shell - script question Here's my data: f1 f2 f3 f4 f5 f6 |02/12/09|12:33PM|3|Oceanview |OVT #1| VISA/MC |02/12/09|12:14PM|3|Oceanview |OVT #1| VISA/MC |02/12/09|09:13AM|4|Oceanview |OVT #1| VISA/MC ... (8 Replies)
Discussion started by: lyoncc
8 Replies

7. Shell Programming and Scripting

Sort question.

Hi Guys, I have a file to be sorted and uniq with the following format. S00001002|01|20021231 S00001002|01|20011031 S00001006|01|20120430 S00001006|01|20111231 S00001006|01|20111031 S00001006|01|20110831 S00001006|01|20110731 S00001006|01|20101231 S00001006|01|20091231... (5 Replies)
Discussion started by: nua7
5 Replies

8. UNIX for Dummies Questions & Answers

Sort command question

I have a file like this: /vol/eng_app_0103z /vol/eng_app_0103z /vol/eng_app_0120z /vol/eng_app_0126z /vol/eng_app_0144z /vol/eng_app_0150z /vol/eng_app_0154z /vol/eng_app_01551z /vol/eng_app_01552z /vol/eng_app_0155z /vol/eng_app_0164z /vol/eng_app_0199zWhen I use the sort command... (3 Replies)
Discussion started by: newbie2010
3 Replies

9. Shell Programming and Scripting

Sort command question

I have a question about what the sort command is doing. Here is some sample data: 348201310013RVE 2 600201310013GFJ 70 3302013020101NS 40 600201309013GFJ 70 The sort command that is running is as follows: sort -k 1,3 -k 12,4 input.txt > output.txt ... (6 Replies)
Discussion started by: Drenhead
6 Replies

10. UNIX for Beginners Questions & Answers

Sort question

Have a text file containing 4 columns, the 4th column is sorted numerically in descending order. The 2nd column is alpha text. Been able to get the 4th column to sort in descending order. The 2nd column sorts correctly but it's also in reverse. Would like to be able to keep the 4th column sort... (8 Replies)
Discussion started by: jimmyf
8 Replies
passwd(4)																 passwd(4)

NAME
passwd - password file SYNOPSIS
/etc/passwd The file /etc/passwd is a local source of information about users' accounts. The password file can be used in conjunction with other naming sources, such as the NIS maps passwd.byname and passwd.bygid, data from the NIS+ passwd table, or password data stored on an LDAP server. Programs use the getpwnam(3C) routines to access this information. Each passwd entry is a single line of the form: username:password:uid: gid:gcos-field:home-dir: login-shell where username is the user's login name. It is recommended that this field conform to the checks performed by pwck(1M). password is an empty field. The encrypted password for the user is in the corresponding entry in the /etc/shadow file. pwconv(1M) relies on a special value of 'x' in the password field of /etc/passwd. If this value of 'x' exists in the password field of /etc/passwd, this indicates that the password for the user is already in /etc/shadow and should not be modified. uid is the user's unique numerical ID for the system. gid is the unique numerical ID of the group that the user belongs to. gcos-field is the user's real name, along with information to pass along in a mail-message heading. (It is called the gcos-field for historical reasons.) An ``&'' (ampersand) in this field stands for the login name (in cases where the login name appears in a user's real name). home-dir is the pathname to the directory in which the user is initially positioned upon logging in. login-shell is the user's initial shell program. If this field is empty, the default shell is /usr/bin/sh. The maximum value of the uid and gid fields is 2147483647. To maximize interoperability and compatibility, administrators are recommended to assign users a range of UIDs and GIDs below 60000 where possible. The password file is an ASCII file that resides in the /etc directory. Because the encrypted passwords on a secure system are always kept in the shadow file, /etc/passwd has general read permission on all systems and can be used by routines that map between numerical user IDs and user names. Blank lines are treated as malformed entries in the passwd file and cause consumers of the file , such as getpwnam(3C), to fail. The password file can contain entries beginning with a `+' (plus sign) or '-' (minus sign) to selectively incorporate entries from another naming service source, such as NIS, NIS+, or LDAP. A line beginning with a '+' means to incorporate entries from the naming service source. There are three styles of the '+' entries in this file. A single + means to insert all the entries from the alternate naming service source at that point, while a +name means to insert the specific entry, if one exists, from the naming service source. A +@netgroup means to insert the entries for all members of the network group netgroup from the alternate naming service. If a +name entry has a non-null password, gcos, home-dir, or login-shell field, the value of that field overrides what is contained in the alternate naming service. The uid and gid fields cannot be overridden. A line beginning with a `-' means to disallow entries from the alternate naming service. There are two styles of `-` entries in this file. -name means to disallow any subsequent entries (if any) for name (in this file or in a naming service), and -@netgroup means to disallow any subsequent entries for all members of the network group netgroup. This is also supported by specifying ``passwd : compat'' in nsswitch.conf(4). The "compat" source might not be supported in future releases. The preferred sources are files followed by the identifier of a name service, such as nis or ldap. This has the effect of incor- porating the entire contents of the naming service's passwd database or password-related information after the passwd file. Note that in compat mode, for every /etc/passwd entry, there must be a corresponding entry in the /etc/shadow file. Appropriate precautions must be taken to lock the /etc/passwd file against simultaneous changes if it is to be edited with a text editor; vipw(1B) does the necessary locking. Example 1: Sample passwd File The following is a sample passwd file: root:x:0:1:Super-User:/:/sbin/sh fred:6k/7KCFRPNVXg:508:10:& Fredericks:/usr2/fred:/bin/csh and the sample password entry from nsswitch.conf: passwd: files ldap In this example, there are specific entries for users root and fred to assure that they can login even when the system is running single- user. In addition, anyone whose password information is stored on an LDAP server will be able to login with their usual password, shell, and home directory. If the password file is: root:x:0:1:Super-User:/:/sbin/sh fred:6k/7KCFRPNVXg:508:10:& Fredericks:/usr2/fred:/bin/csh + and the password entry in nsswitch.conf is: passwd: compat then all the entries listed in the NIS passwd.byuid and passwd.byname maps will be effectively incorporated after the entries for root and fred. If the password entry in nsswitch.conf is: passwd_compat: ldap passwd: compat then all password-related entries stored on the LDAP server will be incorporated after the entries for root and fred. The following is a sample passwd file when shadow does not exist: root:q.mJzTnu8icf.:0:1:Super-User:/:/sbin/sh fred:6k/7KCFRPNVXg:508:10:& Fredericks:/usr2/fred:/bin/csh +john: +@documentation:no-login: +::::Guest The following is a sample passwd file when shadow does exist: root:##root:0:1:Super-User:/:/sbin/sh fred:##fred:508:10:& Fredericks:/usr2/fred:/bin/csh +john: +@documentation:no-login: +::::Guest In this example, there are specific entries for users root and fred, to assure that they can log in even when the system is running stand- alone. The user john will have his password entry in the naming service source incorporated without change, anyone in the netgroup documen- tation will have their password field disabled, and anyone else will be able to log in with their usual password, shell, and home direc- tory, but with a gcos field of Guest /etc/nsswitch.conf /etc/passwd /etc/shadow chgrp(1), chown(1), finger(1), groups(1), login(1), newgrp(1), nispasswd(1), passwd(1), sh(1), sort(1), domainname(1M), getent(1M), in.ftpd(1M), passmgmt(1M), pwck(1M), pwconv(1M), su(1M), useradd(1M), userdel(1M), usermod(1M), a64l(3C), crypt(3C), getpw(3C), getpw- nam(3C), getspnam(3C), putpwent(3C), group(4), hosts.equiv(4), nsswitch.conf(4), shadow(4), environ(5), unistd.h(3HEAD) 28 Jul 2004 passwd(4)
All times are GMT -4. The time now is 03:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy