Recipe 6.6. Searching and Replacing in JOE

 < Day Day Up > 

6.6.1 Problem

You're editing some document and finding a particularly annoying misspelling all over the place. What tools does JOE offer for finding and replacing words, text strings, and punctuation in a document?

6.6.2 Solution

Use the ^K F command for all of your find-and-replace needs. Use special search sequences, which are JOE's regular expressions, for fine-grained, precise searches.

Begin a search with ^K F. Use the up and down arrows to scroll through your previous search and replace terms. ^L continues a search without the replace function.

For example, say you find yourself typing "nucular," even though you know better, because you hear it all day from your annoying coworker. You need to go back through your work and change it to "nuclear." Here's how:

^K F Find (^C to abort): \<nucular\> (I)gnore (R)eplace (B)ackwards Bloc(K) NNN (^C to abort): r Replace with (^C to abort): nuclear Replace (Y)es (N)o (R)est (B)ackup (^C to abort)? r

Note the use of \<\>. This tells JOE to perform a whole-word search. Otherwise, JOE will conduct a literal search for your search string, even if it's inside another word.

Rather than correcting the spelling, you may wish to draw attention to this annoying habit of your coworker by putting quotation marks around the word:

Replace with (^C to abort): "\&"

The result is:

"nucular"

Or you can really go nuts, using:

Replace with (^C to abort): "It's nuclear, not "\&" dammit!!"

which creates:

"It's nuclear, not "nucular" dammit!!"

To find a match only at the beginning of a line, use:

\^nucular

To find a match only at the end of a line, use:

nucular\$

To find empty lines, use:

\^\$

To find whitespace, press the spacebar and tab key inside the square brackets:

\[      ]

To match any character in the square brackets (for doing a case-insensitive search), use:

\[Nn]ucular

To match any number of characters, use:

nu\*r

To match exactly one character, use:

nuc\?l

6.6.3 See Also

  • joe(1)

  • The "Special search sequences" in JOE's online help

     < Day Day Up > 


    Linux Cookbook
    Linux Cookbook
    ISBN: 0596006403
    EAN: 2147483647
    Year: 2004
    Pages: 434

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net