Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a few hundred text files in one directory with lists of users:

&usera
&userb
userc
&userd

note that some do not lead with the &. Also, in some files, the last line does not end with a newline character.

What is the simplest way in a shell script to go through all those files and remove, say userb, ensuring that each existing user remains on its own line?

thanks!

share|improve this question

1 Answer 1

up vote 10 down vote accepted
find /directory -name '*.users' -exec sed -i -r '/^&?userb$/d' {} \;
share|improve this answer
    
thanks! though I had to quote: '{}' the filename reference –  carillonator Sep 3 '10 at 18:51
1  
You should probably change the sed command to '/^&?userb$/d' to avoid deleting, say, "otheruserbeth" by mistake. –  Gordon Davisson Sep 3 '10 at 19:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.