Created
June 13, 2011 16:16
-
-
Save opamp/1023092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby | |
# I'm novice. | |
$ARGS = ARGV.size | |
def option_arg(argv) | |
optq = [] | |
optnumq = argv.size - 2 | |
i = 0 | |
while i < optnumq | |
b = argv[i] | |
if b[0] == "-" then | |
optq << b | |
end | |
i += 1 | |
end | |
rtu = [] | |
optq.each do |hmin| | |
size = hmin.size | |
rtu << hmin[1..size] | |
end | |
rtu | |
end | |
if $ARGS < 2 then | |
print("rgrep -[options] 'pattern' file\n") | |
exit 0 | |
else | |
$SEARCH_PATTERN = Regexp.new(ARGV[$ARGS - 2]) # 検索対象の語 | |
$SEARCH_FIKENAME = ARGV[$ARGS - 1] # 検索ファイル名 | |
end | |
$optionArg = option_arg(ARGV) | |
tfile = open($SEARCH_FIKENAME,"r") | |
# option flag | |
lineprint = false | |
#------------------------ | |
$optionArg.each do |optch| | |
if optch == "n" then | |
lineprint = true | |
end | |
end | |
0.upto(0/(0.0)) do |linecount| | |
cl = tfile.gets | |
if cl =~ $SEARCH_PATTERN then | |
if lineprint == true then | |
print(linecount.to_s + ":" + cl) | |
else | |
print(cl) | |
end | |
end | |
linecount += 1 | |
if tfile.eof? then | |
break | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment