Posted 22 November 2013 - 04:09 PM
This is an implementation of (almost) POSIX grep for computer craft. It uses Lua regular expressions for matching, and this is the only difference between my version and a POSIX complaint one, as far as I can tell.
It is my first real program in Lua.
Grep looks for occurrences of patterns in files. If it finds one, it prints the line that it occurred on. As said before, the patterns are lua regular expressions. The program is called like this:
Multiple patterns can be specified like this:
-F turns on plain matching, aka no character will be seen as magic. -i makes grep ignore case in patterns. -x makes patterns only match if they match the whole line. -v inverts grep's behaviour, it will only print lines that do not match the specified pattern.
-n prints a line number in front of the matching line, while -c only prints a count of matching lines.
-l prints the name of the searched file only once when a pattern has been found.
-s stops the printing of file not found errors.
-E and -q are quietly accepted, but don't do anything (actually, -q works, but os.run doesn't return the correct values)
Grep can be found here or installed using pastebin:
If you find any bugs/inconsistencies please reply in this thread.
It is my first real program in Lua.
Grep looks for occurrences of patterns in files. If it finds one, it prints the line that it occurred on. As said before, the patterns are lua regular expressions. The program is called like this:
grep pattern files
Where pattern is one pattern and files is a list of one or more files.Multiple patterns can be specified like this:
grep -e pattern -e pattern files
Patterns can also be read from a file:
grep -f patternfile files
grep -e pattern -f patternfile files
grep -f patternfile -f patternfile files
-F turns on plain matching, aka no character will be seen as magic. -i makes grep ignore case in patterns. -x makes patterns only match if they match the whole line. -v inverts grep's behaviour, it will only print lines that do not match the specified pattern.
-n prints a line number in front of the matching line, while -c only prints a count of matching lines.
-l prints the name of the searched file only once when a pattern has been found.
-s stops the printing of file not found errors.
-E and -q are quietly accepted, but don't do anything (actually, -q works, but os.run doesn't return the correct values)
Grep can be found here or installed using pastebin:
pastebin get E1PNzrA2 grep
If you find any bugs/inconsistencies please reply in this thread.