#NEWLINE# def main( self ) : #NEWLINE# #INDENT# if self . args . names_only : #NEWLINE# #INDENT# self . print_column_names ( ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( not self . args . columns ) : #NEWLINE# #INDENT# self . argparser . error ( 'You must specify at least one column to search using the -c option.' ) #NEWLINE# #UNINDENT# if ( ( self . args . regex is None ) and ( self . args . pattern is None ) and ( self . args . matchfile is None ) ) : #NEWLINE# #INDENT# self . argparser . error ( 'One of -r, -m or -f must be specified, unless using the -n option.' ) #NEWLINE# #UNINDENT# reader_kwargs = self . reader_kwargs #NEWLINE# writer_kwargs = self . writer_kwargs #NEWLINE# if writer_kwargs . pop ( 'line_numbers' , False ) : #NEWLINE# #INDENT# reader_kwargs = { #NEWLINE# #INDENT# 'line_numbers' : True , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# ( rows , column_names , column_ids ) = self . get_rows_and_column_names_and_column_ids ( ** reader_kwargs ) #NEWLINE# if self . args . regex : #NEWLINE# #INDENT# pattern = re . compile ( self . args . regex ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if self . args . matchfile : #NEWLINE# #INDENT# lines = set ( ( line . rstrip ( ) for line in self . args . matchfile ) ) #NEWLINE# pattern = ( lambda x : ( x in lines ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pattern = self . args . pattern #NEWLINE# #UNINDENT# #UNINDENT# patterns = dict ( ( ( column_id , pattern ) for column_id in column_ids ) ) #NEWLINE# filter_reader = FilteringCSVReader ( rows , header = False , patterns = patterns , inverse = self . args . inverse ) #NEWLINE# output = agate . csv . writer ( self . output_file , ** writer_kwargs ) #NEWLINE# output . writerow ( column_names ) #NEWLINE# for row in filter_reader : #NEWLINE# #INDENT# output . writerow ( row )