How to Spilt /etc/group file in Unix

Spilt /etc/group file


This is an example on how to split a line with the group name "staff"
in the file named "/etc/group". This will work with any file. Just use any
specific words you know are in that line that you cannot vi and follow the
example to split the file and put it back together.

In order to split the 'staff' line in /etc/group into multiple pieces
smaller than the 2048 character per line limit of vi,8000 limit for 5.3,
do the following:

IN this example, the group name is staff.

1.  Create a new directory somewhere, and copy the /etc/group file into
that directory.

2.  Run:

    cat group | sed -n '/staff/p' > staff
    cat group | sed  '/staff/d' > newgroup

These commands will create 2 files, newgroup with all group info except
the  staff line, and staff, with only the staff line.

3.  Run:

    split -b 1000 staff

This will split the staff line into 1000 byte files, and name them xaa,
xab, xac, etc.

4.  Vi each of these files (xaa, xab, xac, etc).  After the first one
(xaa), you
will need to add the group name and id to the beginning but, also change
the name
by adding a '1' to the end and incrementing up for each file:

    staff1:!:1:<userids>
    staff2:!:2:<userids>

You will also need to look at the last userid listed, as the split
command may have put part of it in one file, and the rest in the next
file.  You
will need to combine these parts into one file.  The group line should
end with a userid, and not a comma.

5.  When each file has been edited, and have different group names
(staff, staff1, staff2, etc.) with the same groupid, run the following
to add to
the new group file:

    cat xaa >> newgroup
    cat xab >> newgroup

This will add each line separately to the end of the group file.  The
order in which they occur in the group file doesn't matter.

The newgroup file is complete at this point, and can be used to replace
the /etc/group file.  It would also be a good idea to keep a backup copy
of
the old group file for a while


Post a Comment

Previous Post Next Post