Remove specific line of files on linux

Asked

Viewed 73 times

0

I need to remove a particular line in a file crontab ex:

* * * * * root /home/linaro/funcao1.sh
* * * * * root /home/linaro/funcao3.sh
* * * * * root /home/linaro/funcao4.sh
* * * * * root /home/linaro/funcao5.sh

would like to delete the line

* * * * * root /home/linaro/funcao4.sh

Remembering that this file is not in crontab it will be imported according to the script

tried to use the sed but my deficiency in regular expressions did not allow me to make it work

sed '* * * * * root /home/linaro/funcao4.sh' /home/linaro/mycron.txt

3 answers

1

Could use grep in the form:

grep -v "* * * * * root /home/linaro/funcao4.sh" /etc/crontab > /home/usuario/mycron
mv /home/usuario/mycron > /etc/crontab

1

Use sed -i to replace in the file itself:

sed -i '/* * * * * root \/home\/linaro\/funcao4.sh/d' arquivo

0

I managed to solve ^^

sed '/* * * * * root \/home\/linaro\/funcao4.sh/d' /etc/crontab  > /home/linaro/mycron
cat /home/linaro/mycron > /etc/crontab
rm -rf mycron

Browser other questions tagged

You are not signed in. Login or sign up in order to post.