sed and regular expressions

Hi,
There's a bug using JavaDoc that generates an error if a tag <a...> is found in a javadoc comment, which is not a HTML reference. For example this error is produced with generics. I want to insert an space between "<" and "a". Expression is able to find where this happens using find and grep:

But i'm not able to generate the output expression. I don't know how keep the first part of expressi�n (until "<") add an space, and concatenate with the second part. For example, from:

To:

Just and a space between "List<" and "Almacen".
I'm trying to get all lines using above find command. Use cut -d "<" to separate parts, add an space and finally use sed to substitute in file. But I guess there must be an easy way using sed with regular expressions.

Anyone can help me?

Thanks.


  1. :space: ↩︎

Not sure if I got it - made it a bit more generic so it doesn't matter what kind of character comes after the "<":

echo '* List<AlmacenOrdenacion>). Deber�a pasar...'| sed 's/</< /'
* List< AlmacenOrdenacion>). Deber�a pasar...

I'll try to ask the question in other way. In my Java file I have a line with this text:

* List<AlmacenOrdenacion>). Deber� pasar el id del recinto y el tipo de

And I want to change to:

* List< AlmacenOrdenacion>). Deber� pasar el id del recinto y el tipo de

Just add an space between "List<" and "AlmacenOrdenacion", because of this Javadoc bug.

Now I'm trying to run next command, but it doesn't work. The file doesn't change at all.

Why the file "./AlmacenBo.java" is not modified? It really has a line with that text.

Thanks.

$ cat > AlmacenBo.java
* List<AlmacenOrdenacion>). Deber� pasar el id del recinto y el tipo de


$sed -i 's/List</List< /' AlmacenBo.java

$ cat AlmacenBo.java
* List< AlmacenOrdenacion>). Deber� pasar el id del recinto y el tipo de

I can't tell why sed -i is not working. Maybe write it to a tmp file and mv it back to the original or use perl -i or have something like:

printf 'sed "$\nr infile2\ns/</< /\nw! infile2\n1d\nq!'| ex -

I can't do that because it will replace all List<..> occurrences, and project won't compile.
Only javadoc comments where generic begins with an "A" must be replaced. It's there where bug makes javadoc fail.

I'll try, though I don't understand syntax...

Could be because of encoding charset? If I edit file with gedit I see words like "Deber�" correctly, but with sed (or cat) I see "Deber". It's Spanish and that must be without orthographic mistakes. If that is the problem, is there a way to say sed which is the encoding?

Thanks :wink:

---------- Post updated at 02:08 PM ---------- Previous update was at 01:28 PM ----------

I finally solved!!!
Just before running sed command, I use iconv to convert encoding from ISO-8859-1 to UTF-8. Then sed has no problems to replace.

Thanks all.

That thing with printf and ex I got from a post from vgersh99; excellent thing to print the commands for ex, which has a syntax similar to sed etc. to instruct it what to do with the file. Glad you made it.