in reply to Remove string from file

perl -pi -e's/^TOM\b.*\n//' userlist.txt

Isn't this deleting the pattern from the line, rather than deleting the line itself?

If it's Unix/Linux, you might consider using grep or fgrep with the "-v" switch to skip lines containing a certain pattern.

For example, to remove lines containing "TOM" anywhere in the line, use fgrep ("fixed grep") like this:

% fgrep -v TOM userlist.txt > edited.txt
Or to remove lines containing the word "TOM":
% grep -v "\<TOM\>" userlist.txt > edited.txt

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Remove string from file
by bran4ever (Novice) on May 21, 2006 at 14:03 UTC
    Sorry guys, i meant in the script, not from command i am running a script that can add users and remove users. add users is done, but the remove users, i'm having trouble figuring out..
      What do you have so far?  Can you show some code, even it isn't quite working, so we can see which part needs to be tweaked?

      And what are the specific requirements?  Removing a line (or lines?) that exactly matches/match a given name?  Does it have to work for multiple names, or just one name?  Can the name be anywhere in the line(s)?  Can there be other names in the line, or not?  Does whitespace matter?

      If you can show us the code that you have so far, and pinpoint the exact requirements, I'm sure we can get you farther towards your goal.


      s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/