SED on linux does not work

Asked

Viewed 63 times

0

Good afternoon, I’m having trouble deleting a line in my crontab using sed.

my line is this:

0 1 * * * root shutdown -r +1

my sed that doesn’t work:

sed '/0 1 * * * root shutdown -r +1/g' /etc/crontab  > /home/linaro/mycron

I did a test putting a test word and creating a sed so

sed '/teste/g' /home/linaro/mycron  > /home/linaro/mycron

and so it worked. Can anyone help me with this?

  • 2

    You didn’t escape the metacharacters in the search expression

  • would be like ? what is meta character

1 answer

2

Hello!

I believe that Jefferson Quesado referred to asterisks. That is, rewriting

sed '/0 1 \* \* \* root shutdown -r +1/g' [arquivo-de-entrada] > [arquivo-de-saída]

The backslash in this case indicates that the next metacharacter, which is nothing more than a character with some property distinct from the others, should be interpreted as a normal. But it can also assign alternative function to a common character, as in the case of new lines, usually represented by \n.

In most cases the metaproperty of the * makes your comparison with any character result in coincidence and therefore I suppose that the result obtained has included all lines and not only the expected.

By your posting date, I hope you have at least found an alternative solution long ago. In any case, I hope to help those who pass through here.

Browser other questions tagged

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