Live Chat!

pcregrep, grep based on perl compatible regular expressions

          0 votos

November 20th, 2007 mysurface

grep supposedly support perl regex by specified -P option, but somehow my grep do not support that, it complains this when I trigger with -P
grep: The -P option is not supported
But when you check the manpage of grep, you will see this
-P, –perl-regexp
[...]

Posted in Regular Expression, Text Manipulation, pcregrep, printf | Hits: 22508 | No Comments »

Rename multiple files

* * * * ½ 7 votos

November 5th, 2006 toydi

Often over time, we will want to reorganize a group of files by renaming them.
To rename *.txt to *.bak
(e.g. to rename ham.txt to ham.bak)
for f in *.txt; do mv “$f” “${f%.txt}.bak”; done
To remove ‘new-’ from new-*
(e.g. to rename new-ham.txt to ham.txt)
for f in new-*; do mv “$f” “${f#new-}”; done
${variable%pattern} vs ${variable#pattern}
The funny-looking symbol, ${f%.txt} [...]

Posted in Common, Regular Expression, for, mv | Hits: 71229 | 14 Comments »

square brackets in regular expression

* * * * * 1 votos

October 17th, 2006 mysurface

Previously we have an example on regular expression, but It doesn’t shows the power of square brackets ( [ ] )
Let say you want to search for string fprintf, vprintf and sprintf using grep, usually what you do is
egrep “fprintf|vprintf|sprintf” *.c
You may be ask why don’t just uses the word “printf”? If uses the word [...]

Posted in Regular Expression, Text Manipulation, egrep | Hits: 8173 | 2 Comments »

Regular expression with egrep and ls

* * *     2 votos

October 7th, 2006 mysurface

egrep is actually same as grep -E, it interpret PATTERN as an extended regular expression. Therefore ESCAPE ( \ ) is not needed for certain symbol.
ls is a common tool for listing file that matches the keyword.
Regular expression (RE) is a very important and useful to manipulating strings and text. In this example, I would [...]

Posted in Regular Expression, Symbol, Text Manipulation, egrep, grep, ls | Hits: 15273 | 1 Comment »