0

I'm getting this error

sed: 2: "
/^[[:space:]]*pause$/, ...": expected context address

with this line:

/^[[:space:]]*pause$/,+1d

which works on my debian Ubuntu system.

The full file is

file_in=$1
sed -e'
#
# Delete whole lines
/^<?xml/d
/^<[!]DOCTYPE/d
/^<\(.*html\|.*head\|meta\|.*body\)/d
/^<\(.*table\|.*head\|meta\|.*body\)/d
/^[[:space:]]*<[/]*tr.*>$/d
/storeConfirmation/d
#
# Remove pieces of a line
s/<td>//
s%</*td.*>%%
#
# Replacements - chunks
/^<link/ {
  s/<link rel="selenium.base" href/@link/
  s%[[:space:]]*/>%%
}
/^<title/ {
  s/<title>/feature "/
  s%</title>%" do%
}
/^.*>>>>> / {
  s/^.*>>>>>[[:space:]]*/scenario "/
  s/$/ do/
}
s/-->/"/
s/^.*<<<<<.*/end/
s/<[!]--/#/
/^#/ {
  s/^##/#/
  s/"$//
}
#
# Replacements - characters
/\${/ {
  s/\$/@/g
  s/{//g
  s/}//g
}
s/^[[:space:]]*//
/^[[:space:]]*$/d' $file_in |
sed -e'
/^[[:space:]]*pause$/,+1d
/deleteAllVisibleCookies/d
/click\|wait\|assert/ {
  N;
  s/\n/ /
}
/@.*@/ {
  s/@/+ @/2
}
/select\|type/ {
  N;
  N;
  s/\n/ /g
}
$ a end
'

Sample input

<tr>
        <td>waitForVisible</td>
        <td>${css_delete_violation}</td>
        <td></td>
</tr>
<tr>
        <td>click</td>
        <td>${css_delete_violation}</td>
        <td></td>
</tr>
<tr>
        <td>storeConfirmation</td>
        <td></td>
        <td></td>
</tr>
<tr>
        <td>pause</td>
        <td>2000</td>
        <td></td>
</tr>

I also tried:

/^[[:space:]]*pause$/0,+1d
/^[[:space:]]*pause$/1,+1d
/^[[:space:]]*pause$/+1d
/^[[:space:]]*pause$/1d
/^[[:space:]]*pause$/1,2d

but they all give invalid command code

I also tried:

...
sed -E '
/^[[:space:]]*pause$/,+1d
...
  • 1
    Could you please provide a minimal input file. – Thomas Erker Sep 15 '15 at 15:24
  • Added that to the question. – Michael Durrant Sep 15 '15 at 16:22
4

Linux usually has GNU sed, OS X uses sed from BSD. The address '/pattern/,+1' is a GNU extension, it will not work with other sed implementations.

What might work is the following (joining a line with the next, then deleting the line):

/pattern$/N; /pattern/d

At least that worked on OS X 10.10. Notice the different patterns.

As your goal is to to manipulate an XML file, sed isn't the right tool to begin with. For example have a look at Python and it's lxml module (not part of Python's Standard lib); that combination worked well for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.