Link to home
Start Free TrialLog in
Avatar of member 01
member 01

asked on

Linux(Redhat) : Delete specific line from a file based on matching words

Hi,

I want to delete a specific line from a file in linux (REDHAT).

for ex my file contains :

aniket All = (All) /usr/bin/rootsh
aniket All = (All) /usr/bin/filesh


I want to delete first line based on aniket(username) and rootsh. I mean there should be aniket and rootsh both in the specific line then it should delete the line from the file
Avatar of dfke
dfke

Hi,

you can use sed to remove lines containing multiple strings and then redirect the output to a new file:

sed '/aniket/{/rootsh/d}' originalfile > newfile

Open in new window


Cheers
SOLUTION
Avatar of ssvl
ssvl
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

that ideed does the same exact thing.  But keep in mind that using >> appends the output again at the end of newfile if you run it more than once.

Cheers
Avatar of member 01

ASKER

Hi,

Can you provide a solution for this:

before deleting the information it show the information which is to be deleted.



Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
1. Resolved
2. Tested
3. inactive for 14 days