Ad

Showing posts with label Software - Regex. Show all posts
Showing posts with label Software - Regex. Show all posts

Wednesday, July 9, 2014

SED unix utility explained

SED is a great unix utility that enables you to manipulate the contents of a file with simple regular expressions. Say for instance if you wanted to remove the first line in a file:

sed -i '1d' /filepath/hello.txt

The above command specified to insert the text into the file i.e. modify the file specified after the command.
The '1d' tells sed to delete the first line from the file.

You can also replace text in files e.g:

sed -i 's/text your looking for/text you want to replace it with/' /filepath/hello.txt

The above statement will find the text: "text your looking for" and replace it with "text you want to replace it with" the 's' in the beginning stands for pattern space. The syntax explained:

s/regex/replacement/

Have fun with it!

Wednesday, December 17, 2008

Regular Expressions




A regular expression, or regex for short, is a pattern describing a certain amount of text. On this website, regular expressions are highlighted in red as regex.

This first example is actually a perfectly valid regex. It is the most basic pattern, simply matching the literal text regex. Matches are highlighted in blue on this site.

I will use the term "string" to indicate the text that I am applying the regular expression to. I will highlight them in green.

http://www.regular-expressions.info/quickstart.html

http://www.regular-expressions.info/reference.html