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
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
Hi,
Can you provide a solution for this:
before deleting the information it show the information which is to be deleted.
Thanks
Can you provide a solution for this:
before deleting the information it show the information which is to be deleted.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1. Resolved
2. Tested
3. inactive for 14 days
2. Tested
3. inactive for 14 days
you can use sed to remove lines containing multiple strings and then redirect the output to a new file:
Open in new window
Cheers