Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

extract table names from sql log file

grep "from " /var/log/mysql/mysqld.log | awk -Ffrom '{print $2}' | awk '{print $1}' | cat > /home/shantanu/testing.txt

Ruby Cat

// A Simple Ruby cat program that includes using getoptlong and the rdoc.

#!ruby
# == Synopsis
# Copies files to stdout
#
# == Usage
# ruby cat.rb file1 file2 ... filen
# 
# == Author
# Scott LaBounty
#
# == Copyright
# Copyright(c) 2006 Scott LaBounty
#
#

require 'getoptlong'
require 'rdoc/usage'

##
# Main Program
#

if __FILE__ == $0

    # Set up the command line options
    opts = GetoptLong.new(
        ["--verbose", "-v", GetoptLong::NO_ARGUMENT],
        ["--help", "-h", GetoptLong::NO_ARGUMENT]
        )

    # Set the default values for the options
    verbose = false
    date=""

    # Parse the command line options. If we find one we don't recognize
    # an exception will be thrown and we'll rescue with a RDoc::usage
    begin
        opts.each do | opt, arg|
            case opt
            when "--help"
                RDoc::usage
            when "--verbose"
                verbose = true
            end
        end
    rescue
        RDoc::usage
    end


    ARGV.each do | fileName |
        puts "fileName = #{fileName}" if verbose

        # Make sure the file exists
        if (File.exist?(fileName)) then

            # Open the file
            File.open(fileName) do | file |

                # For each line in the file 
                file.each_line do | line | 
                    puts "#{line}"
                end

            end
        else
            puts "Could not find #{fileName}"
        end
    end
end

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS