Re: regular expression newline replace

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday 05 January 2005 05:43, Larry Howe wrote:
> 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

And the command to strip out blank lines is

cat infile | awk ' { if ($0) print }' > outfile

Larry
___________________________________________________
.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.

[Index of Archives]     [Trinity (TDE) Desktop Users]     [Fedora KDE]     [Fedora Desktop]     [Linux Kernel]     [Gimp]     [GIMP for Windows]     [Gnome]     [Yosemite Hiking]
  Powered by Linux