0

when using sed like this in bash, below message was returned.

bash-3.2$ sed -i 's/\t/ /g' hoge.txt

sed: 1: "hoge.txt": extra characters at the end of h command

I understand that I need a suffix to work this command. But, I couldn't find meaning of "h command". What does it mean ?

tsrrhhh
  • 459
  • 1
  • 5
  • 10
  • The complaint is coming from `sed`. Possibly relevant: http://stackoverflow.com/questions/12833714/the-concept-of-hold-space-and-pattern-space-in-sed – fadden Jun 05 '16 at 02:09
  • It was a very helpful reference. Thanks ! – tsrrhhh Jun 05 '16 at 02:17

1 Answers1

4

The -i parameter to sed takes an argument, so what you think is your sed command is actually the backup filename suffix for the in place edit. Then hoge.txt is being taken as the command to run, hence the error about the h command.

The correct way to do this would be sed -i '' -e 's/\t/ /g' hoge.txt

Using -e isn't strictly required, but by passing it you ensure that sed will treat the next token as the command.

Daenyth
  • 35,856
  • 13
  • 85
  • 124
  • 3
    To expand on this, note that GNU `sed` allows an optional argument for `-i` while BSD `sed` requires an argument. The reference to `bash` 3.2 in the prompt suggests Mac OS X, which uses BSD `sed`. – chepner Jun 05 '16 at 02:21
  • Thank you for your very plain explanation ! – tsrrhhh Jun 05 '16 at 02:22