我正在使用https://github.com/tilo/smarter_csv gem来阅读我的csv文件。在我的代码的最后一行,我写了puts records
来查看函数的输出。
filename = 'db/csv/airports_codes.csv'
options = {
:col_sep => 'tt',
:headers_in_file => false,
:user_provided_headers => [
"id",
"code",
"city",
"country",
"country_code",
"continent",
"coordinate_x",
"coordinate_y"
]
}
records = SmarterCSV.process(filename, options)
puts records
然而,有很多输出,我的终端只显示最后约200个项目。我怎么看别人?
这些是终端顶部显示的前2项。
{:id=>4564, :code=>"YEB", :city=>"Bar River", :country=>"Canada", :country_code=>"CA", :continent=>"North America", :coordinate_x=>"\\N", :coordinate_y=>"\\N"}
{:id=>4565, :code=>"YED", :city=>"Edmonton", :country=>"Canada", :country_code=>"CA", :continent=>"North America", :coordinate_x=>"\\N", :coordinate_y=>"\\N"}
我还要注意,它不允许我在上面滚动。它就像这是终端中的第一行,并且它上面没有任何东西。我正在使用Ubuntu linux。
答案 0 :(得分:1)
由于records
实际上只是一个对象数组,因此您可以将其视为任何数组,并使用slice
将其分解为可查看的部分。
records.slice(20, 10)
将从第21项开始输出10条记录
显然还有其他选择,例如增加终端显示的行数 - 但你应该向http://unix.stackexchange.com提出一个具体问题 - 让他们知道你正在使用哪个终端以及哪个shell环境,等等,有人会帮助你。