A resposta de @rajish usando grep foi aproximada, mas ignorou algo: a pergunta sobre a remoção de linhas idênticas. Por padrão, grep corresponderá a strings (partes de linhas).
POSIX grep tem uma opção adequada:
-x
Consider only input lines that use all characters in the line excluding the terminating newline to match an entire fixed string or regular expression to be matching lines.
Dado que, pode-se usar grep para fazer isso:
cp -f -p input.txt input.txt~
grep -v -x -F -f input.pat input.txt~ >input.txt
onde input.pat contém as linhas a serem removidas, e input.txt é o arquivo a ser atualizado.
A solução de @nvarun usando sed teve um problema semelhante, além de não escapar de / caracteres no arquivo padrão. Este exemplo funciona para mim e limita a sintaxe a POSIX sed :
cp -f -p input.txt input.txt~
sed -e 's/\([\/]\)/\/g' -e 's/^/\/^/' -e 's/$/$\/d/' input.pat > input.sed
sed -f input.sed input.txt~ >input.txt
Apenas para ser arrumado, salve o arquivo original antes de atualizá-lo ( POSIX cp ) .
input.pat
first
this is second
second/third
second\third
input.txt
first
only first should match
this is not first
this is second
the previous line said this is second
first/second/third
second/third
first\second\third
second\third
Resultado:
only first should match
this is not first
the previous line said this is second
first/second/third
first\second\third