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

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

 



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....



Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


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

  Powered by Linux