Re: Getting a text file rid of all superfluous blank lines

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

 



On Mon, 2005-12-05 at 02:09, Mike McCarty wrote:

> > It's rarely worth the trouble to compile a specialized
> > program for anything that can be done with regular
> > expression since the native unix tools are so good
> > at text manipulation.  If you can describe the problem
> 
> For me, it's rarely worth the trouble to read the man
> pages and try to figure out how the weird syntax of
> sed works all over again, when in 5 minutes or so I can
> have a specialized program working.

I agree that the holding space notion is weird.  However
pipelines are not.  I would have used the 2 step solution
myself and been done in one minute without cluttering
my system with bits of some specialized program I'll
never use again.

>  In fact, for *really*
> simple stuff, I just use a keyboard macro for my favorite
> text editor (not vi, and not emacs) and tell it to repeat
> the edit.

Note that vi uses essentially the same syntax as sed
and grep so you only have to learn it once, and in
vi you can practice interactively, using 'u' to 
undo a mistake.  And the motion syntax of vi is the
approximately the same as 'less' so you also learn
to search and page through files.

> > in words, you can usually come up with a sequence of
> > steps to transform what you have into what you want
> > with regular expression substitions. 
> 
> IOW, regular expressions are (1) complicated (2) work
> differently with every tool even with the same OS,

Partly true, but the differences are small and predictable.
If you stick to the original form used in 'ed', they work
the same everywhere and the \char to represent character
classes are usually either all there or not.  The differences
evolved over 30 years or so in discrete steps.  They
aren't just random changes.  And if you use ed, you can
include backward motions in your edit script syntax, but
nobody does that anymore...

> (3) usually take three or four iterations to get right,

Which is why doing them in vi is a good start because you
see the result without extra steps and a simple 'u'ndo
puts it back regardless of the complexity of the change.

> and (4) not portable to other OS,

The free Cygwin tools bring all the useful parts to
windows.  OSX sensibly already has them.  What else do
you care about?  And why use a unix-like system if
you don't want to take advantage of it's toolset?

> whereas a little C
> program (1) is simple to write, (2) has the same
> syntax on all systems, and (3) is portable even to
> my non-hosted environment on my little MC68HC11 machine
> running no OS at all.

Many OS's don't come with a C compiler, and even on the
ones that do, the easiest way to do a lot of text transformations
is to use the regular expression library routines.

-- 
  Les Mikesell
    lesmikesell@xxxxxxxxx



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux