clacker's blog

once more

I was thinking about my last entry and perhaps this one should have come first to make thing clearer. I was trying to show the use of sed for solving a problem. I wanted an example that was complex but still understandable. I was looking for a way to show how to explain the use of pattern and hold buffers in sed. I don't think that's what I got.

The pattern buffer contains the current line. It's what the "s" command performs its replacements to. The hold buffer is another buffer you can use. There are 5 commands (g G h H x) that move thing to and from the hold buffer. You can choose between appending to a buffer or overwriting the buffer. H appends the pattern buffer to the hold buffer, h overwrites the hold buffer with the pattern buffer, G appends the hold buffer to the pattern buffer, and g overwrites the pattern buffer with the hold buffer. x exchanges the hold and pattern buffers

sed and fluxbox menu conversion

I've been working on a sawfish window manager.dsl, and I made a .sawfish file that makes a few of the menu items, but I thought it would be nice to have a fluxbox menu converter (or at least an outline that others could use as well. I played around in sed and I got something that works so I thought I'd share the code, the results, and the sorrows.

The sawfish menu entries, like ion's, are in a different order than fluxbox's. The submenus must be fully defined before they are called by their owner. I looked at bash and C, but for whatever reason, I could see the answer in sed.

My basic strategy was to clean up the file a bit, then use the two buffers in sed to my advantage. Since sed is good at pattern matching, I thought I could use the next read [end] statement to tell me that the last [submenu] in the hold buffer was ready for writing. Then I would write that submenu out and replace everything in the hold buffer past that point with the call to the newly created submenu. Then when the next [end] comes around, you have everything set up. [exec] entries get reformatted and appended to the hold buffer.

right sed Fred

Recently, I wanted to get a word count for an electronic copy I had of a book. Not the normal "number of words" word count, but the number of times each particular word was used. I wanted to know what the most common words he used were. Then I wondered what the most common two word combinations were. I couldn’t think of a good way of doing this except for writing a program, and that looked like a lot of work, so I let the whole project slide. Then I read about sed, and I realized that my goal was much closer and easier to reach than I thought.

Sed is a "stream editor." In a nutshell, it transforms an input stream or file and sends its output to the standard output. It can do things like finding lines containing certain words (like grep), replacing a pattern with another pattern, and replacing characters with other characters (like tr). I was shocked how easy sed was to use after a small learning curve. There are only 24 commands. What I hadn’t know before was the reason for a "non-interactive stream editor" is so that you can pipe input into it, let it manipulate the text, and then do whatever with the output.

The New Frontier

An atom isn’t very dense: there is a probability cloud for the electrons, a very small nucleus, and the rest is empty. If you are in the probability cloud, the chances are high you’re going to be hit. Same goes in the nucleus. Anywhere else and you’re home free. The same is true (I think) as far as knowledge goes: there is a field that non-technical people hang out in, a solid core where computer geeks know what’s what, and the rest is pretty much unexplored. Try to tell a literature major about a book’s style, and they’d kick your but. Try to run a principle component analysis better than a math major and they would take you to task. But look at the space in between and there’s room to move. Linux, because of its flexibility and its depth, is a great way to explore this new frontier of empty space.

Thinking in Linux

I read a comment the other day, where the person said most new Linux users are still thinking in Windows. I made me wonder what that meant. Is it like that Clint Eastwood movie "Firefox Down" where he needs to think in Russian to make the plane fly? What does thinking in Linux mean? What would you do differently if you were "thinking in Linux" instead of "thinking in Windows?"

Power vi

So now you’ve got the basics of vi down, but you’re thinking “so what?” Well Miles, let me tell you. vi has a lot of cool features that a jazz man like yourself is going to be able to riff on for a long while. It isn’t the archaic version of notepad that you think it is. Did you know that vi has 26 unique buffers for you to copy text into, and an additional 10 that save things you’ve deleted? That’s like having 26 clipboards you can use. Have you ever tried opening and changing a file in scite, only to find that you couldn’t save it because you didn’t have permission? In vi that isn’t such a big deal because you can force vi to save the file. Or did you know that you can compile and run the text you’re working on by writing a macro that makes a system call with whatever file you’re working on as the argument? That was one of the things I thought only scite had.

80/20 of vi

I’m going to take back what I said about being able to do 95% of what you need to do in vi. It was pointed out to me that cutting and pasting is well over 40% of what you need text editor for. What kind of text editor can’t cut and paste? So today I’m going to look at cutting and pasting in the vi text editor, and saying that now you’ll know 80% of vi, where the other 20% will take 80% of the time to learn.

vi is the new scite

Scite is my favorite text editor. I like the syntax highlighting and the ease of use. Searching and replacing is easy and every command is easy to find. I thought that I would never find another text editor I liked that much. If you haven't tried the vi editor yet, you're probably going to be as surprised as I was. There is a little learning curve, but it's worth it. It is a very powerful program and it even lets you write your own macros. Here is a really short introduction to vi for newbies that I wish I had when I was learning it.

XML feed