Re: how to search/replace text in mutliple files?

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

 



On Wed, 2004-02-11 at 14:13, 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.)

{e,}grep regex'es are not perl regex'es: try 'e +w' to match multiple
spaces. There exists a -P switch to egrep that should make it understand
perl regex'es

btw if you are going to _replace_ text you should better look at sed or
perl one-liners


-- 
pc




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

  Powered by Linux