Posts

Showing posts with the label Regular Expressions

Linux: rename, rename.ul, prename, perl-rename: what a confusion!

Image
1 Summary of this article. 2 One for all: mv . 3 The rename command: this is where the problems begin! 4 How does the rename command behave that is NOT compatible with regular expressions? 5 The regular expressions compatible commands. 6 The “ sed ” command in GNU/Linux. 7 Using regular expression compatible commands. 1 Summary of this article. In this article I report some observations on how to rename documents in GNU/Linux using text commands, clarifying some differences between various distributions. The rename command does not, in fact, have unique behavior in distributions derived from Debian versus those derived from Fedora and Arch. I will try to clarify the content of different commands and the different behavior of commands that have the same name. All steps were personally tried during the writing of the article. If you find inaccuracies or errors, please let me know. 2 One for a...

Vim Is Magic or Nomagic?

Image
What’s this joke? The title is a joke with the name of “ V.I.M. ” but, at the same time, it’s a real mode of Vim itself: the Magic Mode . To understand what Magic Mode is, the primary source is the item :help magic in Vim. In a few words: - The Magic Mode refers to the regular expressions - The Magic Mode is enabled by default in Vim. - You can explicitly invoke the Magic Mode with the \m command in the RegEx search area. - To deactivate it you must set \M (capitalized m ) in the RegEx search area. - When you use the \M command you invoke the Nomagic Mode . - Nomagic Mode turns “ almost all special regex symbols into ordinary ones unless they start with a backslash ”. - There is also a Very Nomagic Mode that extends the effect to other characters, not relevant to this article. When is magic mode (default) better than nomagic? To analyze the difference between magic and nomagic mode, I resume a formula from a previous article of mine . It’s the Vim RegEx formula for...

Vim: study on transposing lists of names from horizontal to vertical

Image
Primary purpose of the study. Initial status : series of inline names, separated by a semicolon followed by a space. Objective : Transpose all names into one column by removing both semicolons and spaces. Purpose : Creating list for mail-merging with e-mail client ( Thunderbird ). Tools : Vim and built-in RegEx function. Example : From: One@mail; Two@mail; Three@mail; ... To: One@mail Two@mail Three@mail ... Secondary goal To test the integration between Markdown and css tags. This objective was accomplished in the Example above by inserting the following code: <p style = "text-align: center; font-weight: bold;" > Da: </p> <pre> One@mail; Two@mail; Three@mail; ... </pre> <p style = "text-align: center; font-weight: bold;" > A: </p> <pre> One@mail Two@mail Three@mail ... </pre> Vim: regular expression for the primary target To obtain the transposition from horizontal to vertica...

Comparison of Vim and Emacs for a substitution operation using regular expressions

Image
Preface This article is a summary of two previous posts that you can read at these pages: “Vim: Study on constructing Regular Expressions to delete or reduce blank lines with Global Command” “Emacs: Study on constructing Regular Expressions to delete or reduce blank lines” The topic of “regular expressions” in Vim and Emacs is well suited for a functional comparison across the four different scenarios covered in the above articles to which I refer for a description of the syntax. Comparation Table Target Vim Emacs Delete “pure” blank lines :g/^$/d M-x flush-lines <RET> ^$ <RET> Delete blank lines with whitespace :g/^\s*$/d M-x flush-lines <RET> ^\s-*$ <RET> Reduce “pure” blank lines :g/^$\n^$/d M-x query-replace-regexp <RET> ^C-qC-j\{2,\} <RET> C-qC-j <RET> Reduce blank lines with whitespace g/^\s*$\n^\s*$/d ^\(^C-q<SPC>*C-qC-j\)\{2,\} <RET> C-qC-j <RET> Emacs: what you type is n...

Vim: Study on constructing Regular Expressions to delete or reduce blank lines with Global Command

Image
Preface On the topic of this article you may find interesting the following one: “Vim and Regular Expressions for removing redundant whitespace” . Unlike the previous article, here the presence of whitespace causes different solutions than blank lines regardless of the number of their occurrences. The study in this article is focused on both the analysis of “ regular expressions ” and Vim’s global command. Vim and the Global Command The Global Command in Vim is the g key. It’s useful for a lot of purposes. In Normal Mode it can be used to compose multi-letter commands, such as the following ones: guw : lower case next word gUw : upper case next word gU2w : upper case next two word gUe : upper case until the end of the word gu$ : lower case until the end of the line ge : move to the end of the previous word (simple e moves to the end of the next word) … and so on. The g Command can also be a motion operator , as described in this article of mine . The same global ...

Vim and Regular Expressions for removing redundant whitespace

Image
Introduction and structure of the article I wrote this article to practice “in situ” formula construction of Regular Expressions , also called "RegEx", in Vim. In particular, the goal is to “clean up” documents with excess whitespace at both the beginning and end of each line. A basic knowledge of Vim and the Regular Expressions built into the editor is sufficient for understanding the article. The various formulas are applied to whole documents but, since they are very normal search commands in Vim, they can be applied to individual rows or to specific ranges of rows in the context of the document. There are three formulas illustrated and the construction is progressive with “step-by-step” analysis of the syntax of Regular Expressions . The structure of the article is as follows: first I illustrate the creation of the formula for an end-of-line operation; then I move on to the reverse formula, i.e., for the same operation but at the beginning of the line; finally ...

Vim: two methods to append blank lines under multiple text lines

My Table of Contents What are we talking about? The Regular Expression solution The Global Command solution