regular expression newline replace

Larry Howe larry.howe at comjet.com
Wed Jan 5 10:43:58 GMT 2005


On Wednesday 05 January 2005 00:19, James Richard Tyrer wrote:
> Mage wrote:
> >          Hello,
> >
> > I am new with KDE. I like it, but I have noticed that all KDE editors
> > (Quanta, Kate, KWord) fail with replacing newline characters.
> >
> > For example, my regexp is [\n\a\r]*, this should match every type of
> > newlines (unix, ms). It matches, but just finds them and doesn't replace.
> >
> > Is this a bug? I have to install bluefish for this simple task.
>
> I haven't been able to figure out how to remove blank lines with search
> and replace either. :-(
>
> The regexp
>
> 	^ *$\n
>
> is rejected as improper.
>
> So, it is probably a bug.

I'm not sure the \n is really "there" once the file has been loaded into the 
editor. 

^$

will match a blank line. Replace also works, as long as you specify something 
to replace it with. If you leave the replacement text blank, nothing happens. 
I think that is the bug. I tested with Kate. 

Fortunately linux provides a powerful command line.

cat infile | awk 'BEGIN {RS="\n"; ORS="\a"} { print }' > outfile

will replace unix line ends with \a. BTW I did not have good results with 
[\n\a\r]*. It seems to want to match more than just the line end.

Larry
___________________________________________________
This message is from the kde mailing list.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.




More information about the kde mailing list