TitoHL
October 3rd, 2014, 08:32 PM
Hi guys:
I am learning to create scripts, but I've had troubles with SED command. In particular, when I try delete a line that ends with a pattern.
My example is, boot.txt, a text file that contains three lines:
[ 16518 2014-09-23 16:09] /boot/grub/grub.cfg
[ 1024 2014-10-02 14:49] /boot/grub/grubenv
[ 1024 2014-10-02 14:49] /boot/grub/grubenvx
According to the documentation, to remove only the 2nd line (ends with grubenv), I would use the following command:
sed -e '/grubenv$/d' boot.txt > boot2.txt
Theoretically, the result should be that boot2.txt containing:
[ 16518 2014-09-23 16:09] /boot/grub/grub.cfg
[ 1024 2014-10-02 14:49] /boot/grub/grubenvx
However, the result is that the content of boot2.txt remains the same boot.txt.
What am I doing wrong?
In advance, thank you very much.
PS: I know you can use other commands to do this, but my intention is to learn to use either the SED command.
I am learning to create scripts, but I've had troubles with SED command. In particular, when I try delete a line that ends with a pattern.
My example is, boot.txt, a text file that contains three lines:
[ 16518 2014-09-23 16:09] /boot/grub/grub.cfg
[ 1024 2014-10-02 14:49] /boot/grub/grubenv
[ 1024 2014-10-02 14:49] /boot/grub/grubenvx
According to the documentation, to remove only the 2nd line (ends with grubenv), I would use the following command:
sed -e '/grubenv$/d' boot.txt > boot2.txt
Theoretically, the result should be that boot2.txt containing:
[ 16518 2014-09-23 16:09] /boot/grub/grub.cfg
[ 1024 2014-10-02 14:49] /boot/grub/grubenvx
However, the result is that the content of boot2.txt remains the same boot.txt.
What am I doing wrong?
In advance, thank you very much.
PS: I know you can use other commands to do this, but my intention is to learn to use either the SED command.