how to search/replace text in mutliple files?

Keven Ring keven at mitre.org
Wed Feb 11 13:32:16 UTC 2004


Trevor Smith wrote:

>Man, I am completely at a loss how to use a regex to search for whitespace.
>
>I *want* to search and replace some complex strings in multiple HTML files but 
>I can't even successfully SEARCH -- forget about the replace!!
>
>Do regular expressions not actually work to find whitespace?!? I can't make 
>them work, although the regex editor in Kate seems to do the job, when I copy 
>even a simple regex that it produces to the command line for use with grep or 
>egrep, they match exactly nothing.
>
>For example, a test file named "test.file" containing:
>
>some words
>some other words
>
>produces matches with:
>
>grep 'e w' test.file
>
>but NO matches with:
>
>grep 'e\sw' test.file
>egrep 'e\sw' test.file
>grep 'e[\s]w' test.file
>etc.
>
>Now, that's fine if the file I'm searching has ONLY one space, but the WHOLE 
>purpose of regexes is to allow me to search flexibly. I want to search for 
>different lengths of whitespace, etc., but since I can't even search for ONE 
>whitespace character successfully, I'm unable to expand my regex.
>
>Any help? (Eventually I was going to build the regex to look for 
>space/tab/newline characters.)
>
>  
>
According to the manual on grep [man grep], '[:space:]' should be used 
to search for a space

$ cat test.file
some words
some other words
some     words
$ grep "e[[:space:]]*w" test.file
some words
some     words

HTH...

-- 
Keven Ring                      | They called it Paradise
Lead Software Systems Engineer  |   I don't know why...
The MITRE Corporation           | When you call someplace Paradise
(703)883-7026                   |   Kiss it goodbye....



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2801 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20040211/345cdb44/attachment-0001.bin>


More information about the fedora-list mailing list