4

I tried the code as given on delete text between curly brackets

however I am facing this different error regarding event in sed.

file contains:

This is {
{the multiline
text} file }
that wants
{ to {be
changed}
} anyway.

sed ':again;$!N;$!b again; s/{[^}]*}//g' file

what is supposively going wrong in the workout?

Error

N: Event not found.
JigarGandhi
  • 4,820
  • 10
  • 27
  • 38

2 Answers2

7

You have to escape ! to prevent csh/tcsh from performing history expansion. They still do history expansion though you wrote ! in single quote.

Try:

sed ':again;$\!N;$\!b again; s/{[^}]*}//g' file

Or you can write a script an call with -f script.sed (Read sed FAQ).

cuonglm
  • 150,973
  • 38
  • 327
  • 406
  • You can also disable history expansion with `set histchars`. The `histchars` variable contains which characters to use for history expansion (you can reset this to the default with `set histchars = "!^"`). – Martin Tournoij Dec 01 '14 at 12:36
-1

I am not familiar with tcsh but this sounds like a history expansion problem. In bash single quotes prevent history expansion, maybe in tcsh they don't.

You may disable history expansion (I don't know how to do that, though; in bash this is done by set +H).

Another option: Backslash escapes should work. Try

sed_code=":again;\$\!N;\$\!b again; s/{[^}]*}//g"
sed "$sed_code" file
Hauke Laging
  • 88,146
  • 18
  • 125
  • 174
  • I am unable to assign `sed_code=":again;\$\!N;\$\!b again; s/{[^}]*}//g"` as the variable is not assigned. here is one article regarding it. [variable trouble](http://www.grymoire.com/Unix/CshTop10.txt) – JigarGandhi Dec 01 '14 at 10:16
  • @JigarGandhi This is how it would be done in `bash`. You have to translate it to `tcsh` code yourself (or wait for someone who is familiar with it). – Hauke Laging Dec 01 '14 at 10:19
  • It seems to be a law that every (t)csh question has at least one answer from a (knowledgeable) bash/zsh user, with an answer that doesn't apply to tcsh, or doesn't work... – Martin Tournoij Dec 01 '14 at 11:49
  • @Carpetsmoker But you do realize, I hope, that my answer was the first, identified the problem correctly, and pointed at the correct solution. It would be ridiculous to suggest this answer had better not been given. – Hauke Laging Dec 01 '14 at 12:24
  • It doesn't point to a correct solution, since `set +H` doesn't work in `tcsh`, and neither does `sed_code=":again;\$\!N;\$\!b again; s/{[^}]*}//g"`. You did make a good estimate as to the problem, but IMHO this is not enough to qualify as a decent answer. – Martin Tournoij Dec 01 '14 at 12:34