Tag Info

Hot answers tagged

28

I don't think your files are corrupted. Your example line looks like it contains regular text with null bytes between each character. This suggests it's a text file that's been encoded in UTF-16 but the byte-order mark is missing from the start of the file. See http://en.wikipedia.org/wiki/Byte-order%5Fmark Suppose I open Notepad, type the word 'filename', ...


25

You can use regular expressions by clicking on this button: The regex for a Tab character is \t.


19

You can use :%g!/price/d to delete every line that doesn't contain "price"


19

You could try: %s/<CTRL-2>//g (on PC) %s/<CTRL-SHIFT-2>//g (on Mac) where <CTRL-2> means first press down the CTRL on PC, keeping it as pressed down, hit 2, release CTRL. and <CTRL-SHIFT-2> means first press down the control on Mac, keeping it as pressed down, press down shift on Mac, keeping it as pressed down, hit 2, release ...


19

This command will do it (tested on both Mac OS X Lion and Kubuntu Linux). # Recursively find and replace in files find . -name "*.txt" -print0 | xargs -0 sed -i '' -e 's/foo/bar/g' Here's how it works: find . -name '*.txt' finds, in the current directory (.) and below, all files whose names end in .txt | passes the output of that command (a list of ...


17

Search and Replace Search for ~* Replace with whatever. Cheers!


16

:g/pattern/ matches all the lines were pattern is found. :v/pattern/ does the opposite. See :h global for more details. You can use it like this: :v/pattern/norm Ipattern not found - <CR> to prepend "pattern not found - " to every line that doesn't have "pattern" or :v/pattern/s/nrettap/pattern to replace "nrettap" with "pattern" on every ...


13

Within notepad there is no way to use the Find and Replace and target blank lines. Consider Notepad++ and the regex search and replace. You can use \r\n to find blank lines from text files made within Windows, \r for Mac and \n for Linux. I believe a default install actually comes with TextFX to make your life even easier, it has an option to delete blank ...


12

This actually worked for me within vim: :%s/\%x00//g


12

grepWin (not to be confused with Windows Grep) can do this. It supports text-based search and replace, as well as regular expression search and replace: grepWin is free and open source.


12

Please make sure you have a backup in case something goes wrong. In Notepad++ go to Search → Replace In the Find What textbox paste the following: youtubehd:\w\w\w\w\w\w\w\w In the Replace With textbox paste the following: youtubehd Ensure that Search Mode is set to Regular expression Click Replace All Thanks to KCotreau for pointing out that search ...


11

vbScript should do it for you. Create a file called "rename_underscores.vbs" containing the following. Set objFso = CreateObject("Scripting.FileSystemObject") Set Folder = objFSO.GetFolder("c:\test\") For Each File In Folder.Files sNewFile = File.Name sNewFile = Replace(sNewFile,"_"," ") if (sNewFile<>File.Name) then ...


8

Yes you can, I just tried to record a new macro, did a search and replace and it succesfully saved the action so when I played the macro, it did the same search and replace action. I am not an expert at Notepad++ Macros, but I am guessing you are... I opened a random file and created a macro called test. It looked for a word called "snip" and replaced it ...


8

Notepad++ allows you to use capture groups in the search regex, and then refer to those in the replacement. so, use the search term ([0-9])\t([0-9]). The parentheses tell Notepad++ to "capture" the part of the text that matches that part of the regex - in this case, the numbers before and after the tab. In your replacement expression, refer to those ...


8

Use the "Extended" setting in the Replace window (not "Regular expression": I'm sure there's a way to do it with Regular expression, but using "Extended" works fine). Enter ".pPrev.\r\n" in the "Find what" field, and leave the "Replace what" field blank. This will include the \r\n characters in the match and delete the whole line.


7

Fairly basic. Use sed with file globbing. Unless you mean every file in directory and subdirectories? sed -i 's/string1/string2/g' /path_to_dir/* Edit: In the case of literally everything under the directory find /path_to_dir/ -type f -exec sed -i 's/string1/string2/g' '{}' +


7

The short answer: Yes, but it's harder than you think. The long answer: Ordinary find-and-replace code operates on a morphological level, that is, by looking at the form of a text rather than by understanding its meaning. But there is no morphological indication to differentiate the objective and possessive cases of the third-person female pronoun, so ...


6

This would delete all lines that don't contain foo. :g/^\(.*foo\)\@!.*$/d Instead, you could also use :v to reverse the sense of search pattern. :v/\(foo\)/d You can read more about the way :g and :v work here. And more on defining ranges, use of metacharacters etc. for search and replace here.


6

The Scripting Guy covers how to do this in PowerShell (no additional downloads on most recent Windows OSs, you probably already have it installed). Start it up, run the following (to replace a * with a @): (Get-Content C:\Scripts\Test.txt) | Foreach-Object {$_ -replace "\*", "@"} | Set-Content C:\Scripts\Test.txt This supports .NET regular expressions, ...


6

\b(?:(T)|t)own(s?)\b → (?1:\u)village$2 (And uncheck ignore case in the dialog) \b = word boundary (?:) = non-capturing group (?1:\u) = if captured group 1 then convert next character to uppercase


6

Take a look at Sed. You can easily achieve your goal by only one command line sed -e "s/Text_1/TextA/" -e "s/Text1/TextB/" <your_file.txt>your_file_new.txt


6

Go to Find (Ctrl + F) -> tab Replace -> click More... -> Special -> End of paragraph. The symbol is ^p. You can use it in both directions. I have MS Office 2007, but it should work in older versions too.


5

According to Helixoft: Multiline Search and Replace in Visual Studio you can enable Regular Expressions and then use \n to indicate a new line.


5

Use a combination of find(1) and sed(1): # Find all files under the directory hierarchy rooted at 'root', and replace # all instances of the regular expression 'pattern' with 'replacement' in all # of those files: find root -type f -exec sed -i~ 's/pattern/replacement/g' '{}' '+' If you run into command line length limitations, replace the '+' at the end ...


5

In the Replace dialog (Ctrl+H), use the following: Find what: %(.+)% Replace with: $\1 Search Mode: Regular expression


5

"It Depends." You'll probably need a couple things: First of all, the text can't have been rasterized. If that's the case, then all bets are off. Second, the entire font must have been embedded. If the font was subsetted (which is most often the case) then you may not have the required glyphs. Finally, you'd probably want to limit the size of the ...


5

Yes. Use the g command to operate on lines matching a pattern, along with the d command to delete those lines. g/pattern/d So: g/\\\(begin\|end\){frame}/d should do the trick. If that doesn't work, try: :g/\v\\(begin|end)\{frame\}/d which will work, no matter what your magic setting is.


5

I'd use Perl for this: perl -0pe 's/<h1>Title.*\n.*<br>/replacement/' filename.html Here, -0 makes Perl split records on the NUL character instead of reading line-by-line, which is the default when using the -p option. With Perl regular expressions you need .* to match any character multiple times, and you match the newline with \n. ...


5

I would recommend you abandon regex entirely - it is simply too much trouble to get it to work in cases like this. Not everything can be solved easily with regex! In this case, most scripting languages can do this fairly easily. I've written a piece of JavaScript for you, here - just enter your delimiters and input, and click submit. As for an explanation: ...


4

You may want to try one of the align plugins on vim.org. I use the most popular one by Dr. Campbell: http://www.vim.org/scripts/script.php?script_id=294 That aside, though, yes, you can call Vim functions from a substitute command, but the drawback is that the entire replacement pattern has to be an expression. See ":help sub-replace-expression" and ":help ...



Only top voted, non community-wiki answers of a minimum length are eligible