Tags:
create new tag
, view all tags
A page to list (and allow comparison) of commands to perform various tasks in Awk, Sed, Perl, and Nedit. (Of course, I may not initially (or ever) know how to do the same task in all of them, so I'll just fill in what I know and add to it as I get a chance / as it seems worthwhile.)

Hmm, should I try a table, or just headings somehow — a table may get very wide but I may try it just to see.

Of course, Nedit is an editor (a traditional editor?) while Awk, Sed, and Perl are scripting languages or stream editors, so the first step in Nedit is to load the file into Nedit and the last step is to save the changed file and close Nedit. The intent is not to claim that Nedit has the same capabilities, but rather to be able to use the Nedit command as sort of a "benchmark" for comparing the commands in Awk, Sed, and Perl. (Not a performance benchmark, but more a syntax benchmark.)

See:

Contents

Deleting Blank Lines from a File

Note that, IIUC, all of these commands will work only for completely blank lines — lines that contain whitespace characters only, and thus appear blank, will not be removed.

Awk

awk 'NF>0' <text_file>

Sed

sed '/^$/d' <text_file>

Perl

perl

Nedit

With the file open in Nedit, command expressed as a "macro":

Hmm, thinking — as a macro, this is an attempt, but not quite correct, as it will not handle two consecutive blank lines properly. Try it, if you wish — in a long string of blank lines, it will remove every other one on the first pass. Of course, you could do multiple passes. wink

replace_find("\\n\\n", "\\n", "forward", "regex")

Also tried this, but it doesn't delete any lines at all:

replace_find("^$", "", "forward", "regex")

Probably need to do one of the fancier things (can't think of the name) but like a back reference or forward reference or something similar. Not that urgent / interesting to me ATM.

Template for Next Task

Awk

awk

Sed

sed

Perl

perl

Nedit

With the file open in Nedit, command expressed as a "macro":

==

Credits

The awk and sed commands for deleting blank lines from a file came from the UNIX GURU UNIVERSE: UNIX HOT TIP: Unix Tip 2076 of September 7, 2003. I'm not sure I'll credit every command I run across — I've copied the command lines only, not the rest of their text (the other text above is mine), and that little bit of copying probably falls under the realm of fair use or the one about the limited possibilities for expression. Still, I want to give credit where credit is due, I think, until it gets out of hand. I'll see where the next commands come from. Two asides:

  • Their description of the commands is that it suppresses blank lines — I think deleting blank lines is a more appropriate description, as, unless I misunderstand, the blank lines are deleted from the original file, not suppressed in a printout or copy of the file.

  • The attempt at the equivalent in Nedit is "all mine".

Contributors

  • () RandyKramer - 07 Sep 2003
  • If you edit this page: add your name here; move this to the next line; and if you've used a comment marker (your initials in parenthesis), include it before your WikiName.

Revision Comment

  • %DATE% —

Page Ratings

Topic revision: r1 - 2003-09-07 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look