Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

sed '/\r$/ {N s/\n//}'
sed: -e expression #1, char 10: extra characters after command

I want to understand what is wrong with my command line. When I can do the some of following in a script but not in a command line.

I have been working through the tutorial at www.grymoire.com. When I got stuck at the section Working with Multiple Lines. These script works fine.

#!/bin/sh
sed '
# look for a "#" at the end of the line
/#$/ {
# Found one - now read in the next line
    N
# delete the "#" and the new line character, 
    s/#\n//
}' file

In my case I am looking for \r or return ^M.

#!/bin/sh
sed '
# look for a "#" at the end of the line
/\r$/ {
# Found one - now read in the next line
    N
# delete the "#" and the new line character, 
    s/\r\n//
}' file

The problem is when I try to convert it to a single line shell command it gives me an errors.

sed '/\r$/ {N s/\n//}'
sed: -e expression #1, char 10: extra characters after command
sed '/\r$/{N s/\n//}'
sed: -e expression #1, char 9: extra characters after command
sed '/\r$/{Ns/\n//}'
sed: -e expression #1, char 8: extra characters after command

I want to understand what is wrong with my command line. When I can do the following in a script but not in a command line.

I have created a sed script to do the work I want.

cat test.sed 
#!/bin/sed -f
/\r$/ {
N 
s/\n//
}
share|improve this question
up vote 3 down vote accepted

You need to use a semicolon ; to separate sed commands on the same line. Specifically, between the N and s. No semicolon is needed when there is a newline which is why your script form works.

change

sed '/\r$/ {N s/\n//}'  

to

sed '/\r$/ {N; s/\n//}'
             ^
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .