pcregrep, grep based on perl compatible regular expressions

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 Interpret PATTERN as a Perl regular expression. I found […]

Posted in pcregrep, printf, Regular Expression, Text Manipulation | Hits: 145315 | 3 Comments »

Rename multiple files

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 […]

Posted in Common, for, mv, Regular Expression | Hits: 200138 | 29 Comments »

square brackets in regular expression

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 […]

Posted in egrep, Regular Expression, Text Manipulation | Hits: 85577 | 7 Comments »

Regular expression with egrep and ls

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, […]

Posted in egrep, grep, ls, Regular Expression, Symbol, Text Manipulation | Hits: 90985 | 4 Comments »