|
Home > Archive > Unix Shell > May 2007 > remove text
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi all..
I'm in need of some help.
I currently manage a subversion server with many repositories and many
users in the repositories.
When a user no longer requires access to any repo, I have to go into
each repo one by one and remove their name.
The password file is a simple text file located at */conf/passwd
Is there a way that a script can search through all repos and delete
each occurrence of the user?
for example, I can find out which repository the user is a member of
by doing:
grep -l "dan" */conf/passwd
This will look through each repo and print the subdirectory of the
group of which dan is a member of.
How can I then automatically remove his name?
I don't know the command I need to use -- if someone can tell me the
command I can build the script..
| |
| Ed Morton 2007-05-17, 1:19 am |
| Ivan wrote:
> Hi all..
>
> I'm in need of some help.
> I currently manage a subversion server with many repositories and many
> users in the repositories.
> When a user no longer requires access to any repo, I have to go into
> each repo one by one and remove their name.
> The password file is a simple text file located at */conf/passwd
>
> Is there a way that a script can search through all repos and delete
> each occurrence of the user?
>
> for example, I can find out which repository the user is a member of
> by doing:
> grep -l "dan" */conf/passwd
That would produce a false "hit" if "daniel" appeared anywhere in the
file or if "dan" just happened to appear somewhere other than the "user
id" field. If the file is colon-delimited fields and the user id occurs
in, say, the first field, then this would be more accurate:
awk -F: '$1 == "dan"{print FILENAME}' */conf/passwd
> This will look through each repo and print the subdirectory of the
> group of which dan is a member of.
dan or daniel or rodan or....
> How can I then automatically remove his name?
for file in */conf/passwd
do
awk -F: '$1 == "dan"{next}1' "$file" > tmp &&
mv tmp "$file"
done
> I don't know the command I need to use -- if someone can tell me the
> command I can build the script..
Regards,
Ed.
| |
| Chris F.A. Johnson 2007-05-17, 7:18 pm |
| On 2007-05-17, Ivan wrote:
> Hi all..
>
> I'm in need of some help.
> I currently manage a subversion server with many repositories and many
> users in the repositories.
> When a user no longer requires access to any repo, I have to go into
> each repo one by one and remove their name.
> The password file is a simple text file located at */conf/passwd
>
> Is there a way that a script can search through all repos and delete
> each occurrence of the user?
>
> for example, I can find out which repository the user is a member of
> by doing:
> grep -l "dan" */conf/passwd
grep -l "^dan:" */conf/passwd
> This will look through each repo and print the subdirectory of the
> group of which dan is a member of.
>
> How can I then automatically remove his name?
>
> I don't know the command I need to use -- if someone can tell me the
> command I can build the script..
grep -v "^dan:" "$file" > tempfile && mv tempfile "$file"
Or:
sed '/^dan:/d' "$file" > tempfile && mv tempfile "$file"
Or:
awk '/^dan:/ { next } { print }' > tempfile && mv tempfile "$file"
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
|
|
|
|
|