Id like to delete a line from a file using (preferably a single line unix command) if it contains a certain string pattern.
If line contains "abcdef" then delete that line.
Help greatly appreciated.
Id like to delete a line from a file using (preferably a single line unix command) if it contains a certain string pattern.
If line contains "abcdef" then delete that line.
Help greatly appreciated.
# grep -v "abcdef" file > newfile
sed -i "/abcdef/d" <filename>. this will remove the abcdef from the existing file. (take backup of the existing file before removing , if required)
I know that. I want to say if abcdef is in the line then delete the ENTIRE line.
Anyone know how I can do that?
I need to do a huge number of files so while Im grateful for the first reply I cant go with it.
have you tried the proposed code?
Did it work? If not, what errors are you getting?
Why is that?
I dont want to use the first one because I will need to run a command on on thousands of files. The second command didnt work. It didnt like the 'd' at the end of the command.
If you must know its because a trojan filled them with large lines of code. There are a few patterns it left so Im hoping to delete them all in one go.
The lines are painstakingly long so i cant just implement a sed command
so why don't you put the command in a loop - processing one file at a time?
strange - worked fine here. I don't the GNU sed with '-i' implemented, but the standard 'sed' did the job.
Why cannot you implement 'sed'? Have you tried it?
Hi Cronjob78,
Have to tried this command " sed -i "/abcdef/d" <filename>. " ???. This command not only removes the string adcdef, this will remove the entire line. I beleive i have posted this command only after testing.
------------------------------------------
See the below example......
-sh-3.1$ grep ABC aps*
aps1.txt:ABC
aps1.txt:ABC123
aps1.txt:123ABC
aps1.txt:ABCDEFGH
aps1.txt:ABCDE123
aps1.txt:123456789ABC
aps2.txt:ABCDEFGHIJKLMNOP
aps2.txt:PRABHUABC
aps2.txt:SHANKAR ABC
aps2.txt:--ABC---
-sh-3.1$ sed -i "/ABC/d" aps*txt
-sh-3.1$ grep ABC aps*