BSD sed: extra characters at the end of d command

lutaoact

I use sed command on mac OS, following is the text.

$ cat pets.txt 
This is my cat
  my cat's name is betty
This is your dog
  your dog's name is frank
This is your fish
  your fish's name is george
This is my goat
  my goat's name is adam

when I run: (BSD sed)

$ sed '3,6 {/This/d}' pets.txt

It show error:

sed: 1: "3,6 {/This/d}": extra characters at the end of d command

what's wrong with it? when I use gsed(GNU sed), it works well.

Jonathan Leffler

The simplest solution is to put a semi-colon after the d (the spaces shown are optional):

sed -e '3,6 { /This/d; }' pets.txt

BSD sed is fussier about the layout than GNU sed. There are a number of GNU extensions that are not part of BSD sed, and this is one. The semi-colon isn't the universal solution to problems, though it does solve many of them. You could also spread the commands out over multiple lines, or put them in multiple -e options, or various other 'tricks'.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

sed extra characters at end of l command

From Java

How to fix sed command on MacOS with error extra characters after \ at the end of c command?

From Dev

sed error complaining "extra characters after command"

From Dev

sed on mac: 'extra characters after p command'

From Dev

sed: -e expression #1, char 10: extra characters after command

From Dev

why "extra characters after command" error shown for the sed command line shown?

From Dev

Sed matches unwanted extra characters

From Dev

Sed - How do I remove the extra characters that show up after running the command?

From Dev

how to make my sed command work in GNU works in BSD

From Dev

Extra characters added to end of string in c

From Dev

Android:ellipsize end - Extra Characters after Ellipsis

From Dev

Sed command filtering extra text/removing

From Dev

strings command printing some extra characters

From Dev

Removing characters at end of lines using find and sed

From Dev

sed command does not work for certain characters in unix

From Dev

What is the purpose of those special characters in the sed command?

From Dev

fedora sed command replace special characters

From Dev

Sed command for deleting an inclusive range of characters

From Dev

sed command to delete a string containing / ,\ characters

From Dev

(Sed) Search/Replace Involving Negative Number Yields Extra Characters

From Dev

Newlines in BSD sed vs gsed

From Dev

sed command to replace a string with special characters with another string with special characters

From Dev

How can I prevent extra characters at the end of my string in Regex?

From Dev

spring3 file upload and save - extra null characters at the end

From Dev

Excel 2016 - JSON web query - extra characters at the end of JSON input

From Dev

Why is an extra space getting removed in sed substitution command

From Dev

cat command appears to be adding extra $ character at the end of each line

From Dev

Bash sed: Replace all special characters (Invalid range end)

From Dev

equivalent command `route -n` in BSD

Related Related

  1. 1

    sed extra characters at end of l command

  2. 2

    How to fix sed command on MacOS with error extra characters after \ at the end of c command?

  3. 3

    sed error complaining "extra characters after command"

  4. 4

    sed on mac: 'extra characters after p command'

  5. 5

    sed: -e expression #1, char 10: extra characters after command

  6. 6

    why "extra characters after command" error shown for the sed command line shown?

  7. 7

    Sed matches unwanted extra characters

  8. 8

    Sed - How do I remove the extra characters that show up after running the command?

  9. 9

    how to make my sed command work in GNU works in BSD

  10. 10

    Extra characters added to end of string in c

  11. 11

    Android:ellipsize end - Extra Characters after Ellipsis

  12. 12

    Sed command filtering extra text/removing

  13. 13

    strings command printing some extra characters

  14. 14

    Removing characters at end of lines using find and sed

  15. 15

    sed command does not work for certain characters in unix

  16. 16

    What is the purpose of those special characters in the sed command?

  17. 17

    fedora sed command replace special characters

  18. 18

    Sed command for deleting an inclusive range of characters

  19. 19

    sed command to delete a string containing / ,\ characters

  20. 20

    (Sed) Search/Replace Involving Negative Number Yields Extra Characters

  21. 21

    Newlines in BSD sed vs gsed

  22. 22

    sed command to replace a string with special characters with another string with special characters

  23. 23

    How can I prevent extra characters at the end of my string in Regex?

  24. 24

    spring3 file upload and save - extra null characters at the end

  25. 25

    Excel 2016 - JSON web query - extra characters at the end of JSON input

  26. 26

    Why is an extra space getting removed in sed substitution command

  27. 27

    cat command appears to be adding extra $ character at the end of each line

  28. 28

    Bash sed: Replace all special characters (Invalid range end)

  29. 29

    equivalent command `route -n` in BSD

HotTag

Archive