{"id":229789,"date":"2014-07-14T14:36:03","date_gmt":"2014-07-14T10:36:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=229789"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=229789","title":{"rendered":"<span class=\"post_title\">\u0410 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 Ruby?<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       \u041c\u043d\u043e\u0433\u0438\u0435 \u043d\u0435 \u0437\u043d\u0430\u044e\u0442 \u043e \u0442\u0435\u0445 \u043c\u043e\u0449\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0447\u0442\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 Ruby. \u041e\u043d\u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043a\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043e\u043a\u0430\u0437\u0430\u043b \u043d\u0430 \u044f\u0437\u044b\u043a Perl \u0438 \u0447\u0442\u043e Ruby \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0442\u0441\u0440\u0443\u043c\u0435\u043d\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  \u041f\u0443\u0441\u0442\u044c \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0443 \u043d\u0430\u0441 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u0414\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043a\u0430\u043a CSV, \u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u043e \u0441\u0442\u0440\u0430\u043d\u0435. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430:<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code>% wc -l 1005 data.csv % head data.csv # Copyright 2014 Acme corp. All rights reserved. # # Please do not reproduce this file without including this notice. # =============================================================== Name,Partner,Email,Title,Price,Country Nikolas Hamill,Emely Langosh Sr.,nash@moen.info,Awesome Wooden Computer,42261,Puerto Rico Friedrich Zboncak MD,Ms. Trycia Sporer,nils@treutelrodriguez.name,Sleek Wooden Hat,35701,Suriname Marcus Nicolas,Margot Hoppe,maeve@hilll.info,Rustic Steel Shoes,40258,Argentina Toni Ernser I,Guillermo Kihn II,clara.marvin@west.net,Sleek Cotton Pants,68332,Turks and Caicos Islands Mayra Kerluke DDS,Marvin Lynch,sydni.schuppe@schuster.com,Incredible Steel Gloves,47017,New Zealand <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c CSV \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Ruby \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0441\u0435 \u0440\u0443\u0447\u043a\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"ruby\">!\/usr\/bin\/env ruby -w # \u0421\u043a\u0440\u0438\u043f\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0444\u0430\u0439\u043b\u044b, \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0449\u0438\u0435 \u043a\u0430\u043a CSV # \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438 \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0435 \u043e \u0421\u0443\u0440\u0438\u043d\u0430\u043c  # \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 input_record_separator  = &quot;\\n&quot; field_separator         = ',' output_record_separator = &quot;\\n&quot; output_field_separator  = ';' filename = ARGV[0]  File.open(filename, 'r+') do |f|    # \u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0432\u0435\u0441\u044c \u0444\u0430\u0439\u043b \u0432 \u043c\u0430\u0441\u0441\u0438\u0432   input = f.readlines(input_record_separator)   output = ''    input.each_with_index do |last_read_line, i|      # \u0423\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0441\u0442\u0440\u043e\u043a\u0438     last_read_line.chomp!(input_record_separator)      # \u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u043f\u043e\u043b\u044f     fields = last_read_line.split(field_separator)      # \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043d\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043e \u0421\u0443\u0440\u0438\u043d\u0430\u043c     if fields[5] == 'Suriname' && !(last_read_line =~ \/^# \/)        # \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u043f\u043e\u043b\u044f \u043d\u0430\u0448\u0438\u043c\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f\u043c\u0438       fields.unshift i       output &lt;&lt; fields.join(output_field_separator)       output &lt;&lt; output_record_separator     end   end    # \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0447\u0430\u043b\u0443 \u0444\u0430\u0439\u043b\u0430 \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c output   f.rewind   f.write output   f.flush   f.truncate(f.pos) end <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u0439 \u043a\u043e\u0434 \u0432 \u043c\u043e\u0435\u0439 \u0436\u0438\u0437\u043d\u0438, \u043d\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443.  <\/p>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/h4>\n<p>  \u0414\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u044f\u0441\u043d\u0438\u0442\u044c \u0438\u0445 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 english:  <\/p>\n<pre><code class=\"ruby\">#!\/usr\/bin\/env ruby -w require 'english' $INPUT_RECORD_SEPARATOR  = &quot;\\n&quot; $FIELD_SEPARATOR         = ',' $OUTPUT_RECORD_SEPARATOR = &quot;\\n&quot; $OUTPUT_FIELD_SEPARATOR  = ';' filename = ARGV[0]  File.open(filename, 'r+') do |f|   input = f.readlines(input_record_separator)   output = ''   input.each_with_index do |last_read_line, i|     $LAST_READ_LINE = last_read_line     $INPUT_LINE_NUMBER = i     $LAST_READ_LINE.chomp!($INPUT_RECORD_SEPARATOR)     $F = $LAST_READ_LINE.split($FIELD_SEPARATOR)     if $F[5] == 'Suriname' && !($LAST_READ_LINE =~ \/^# \/)       $F.unshift $INPUT_LINE_NUMBER       output &lt;&lt; $F.join($OUTPUT_FIELD_SEPARATOR)       output &lt;&lt; $OUTPUT_RECORD_SEPARATOR     end   end   f.rewind   f.write output   f.flush   f.truncate(f.pos) end <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/h4>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u0430\u043c\u0438\u043c Ruby, \u043e\u043d\u0438 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0442 \u043e\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a\u043e\u0434 \u043a \u0442\u0430\u043a\u043e\u043c\u0443 \u0432\u0438\u0434\u0443:  <\/p>\n<pre><code class=\"ruby\">#!\/usr\/bin\/env ruby -w require 'english' $FIELD_SEPARATOR         = ',' $OUTPUT_RECORD_SEPARATOR = &quot;\\n&quot; $OUTPUT_FIELD_SEPARATOR  = ';' filename = ARGV[0]  File.open(filename, 'r+') do |f|   input = f.readlines   output = ''   input.each_with_index do |last_read_line, i|     $LAST_READ_LINE = last_read_line     $INPUT_LINE_NUMBER = i     $LAST_READ_LINE.chomp!     $F = $LAST_READ_LINE.split     if $F[5] == 'Suriname' && !($LAST_READ_LINE =~ \/^# \/)       $F.unshift $INPUT_LINE_NUMBER       output &lt;&lt; $F.join       output &lt;&lt; $OUTPUT_RECORD_SEPARATOR     end   end   f.rewind   f.write output   f.flush   f.truncate(f.pos) end <\/code><\/pre>\n<p>  \u041c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f $INPUT_RECORD_SEPARATOR. \u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c IO#print, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e $OUTPUT_FIELD_SEPARATOR. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 $OUTPUT_RECORD_SEPARATOR, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0430.  <\/p>\n<pre><code class=\"ruby\">#!\/usr\/bin\/env ruby -w require 'english' $FIELD_SEPARATOR         = ',' $OUTPUT_RECORD_SEPARATOR = &quot;\\n&quot; $OUTPUT_FIELD_SEPARATOR  = ';' filename = ARGV[0]  File.open(filename, 'r+') do |f|   input = f.readlines   f.rewind   input.each_with_index do |last_read_line, i|     $LAST_READ_LINE = last_read_line     $INPUT_LINE_NUMBER = i     $LAST_READ_LINE.chomp!     $F = $LAST_READ_LINE.split     if $F[5] == 'Suriname' && !($LAST_READ_LINE =~ \/^# \/)       $F.unshift $INPUT_LINE_NUMBER       f.print *$F     end   end   f.flush   f.truncate(f.pos) end <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043c\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u043e\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 output. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u0444\u0430\u0439\u043b \u0432 \u043c\u0430\u0441\u0441\u0438\u0432, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e:  <\/p>\n<pre><code class=\"ruby\">#!\/usr\/bin\/env ruby -w require 'english' $FIELD_SEPARATOR         = ',' $OUTPUT_RECORD_SEPARATOR = &quot;\\n&quot; $OUTPUT_FIELD_SEPARATOR  = ';' filename = ARGV[0]  File.open(filename, 'r+') do |f|   while f.gets     $LAST_READ_LINE.chomp!     $F = $LAST_READ_LINE.split     if $F[5] == 'Suriname' && !($LAST_READ_LINE =~ \/^# \/)       $F.unshift $INPUT_LINE_NUMBER       f.print *$F     end   end end <\/code><\/pre>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c IO#gets \u0447\u0442\u043e\u0431\u044b \u0447\u0438\u0442\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c $LAST_READ_LINE \u0438 $INPUT_LINE_NUMBER. \u0422\u0430\u043a \u0436\u0435 \u043c\u044b \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u043e\u0442\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u0444\u0430\u0439\u043b.  <\/p>\n<h4>\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 in-place<\/h4>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0444\u043b\u0430\u0433\u0438 -n -i \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043a\u0430\u0437\u0430\u0442\u044c Ruby \u0447\u0438\u0442\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f IO#gets \u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e IO#print \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0444\u0430\u0439\u043b. \u0414\u043b\u044f -i \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d backup-\u0444\u0430\u0439\u043b.  <\/p>\n<pre><code class=\"ruby\">#!\/usr\/bin\/env ruby -w -n -i require 'english' BEGIN {   $FIELD_SEPARATOR         = ','   $OUTPUT_RECORD_SEPARATOR = &quot;\\n&quot;   $OUTPUT_FIELD_SEPARATOR  = ';' }  $LAST_READ_LINE.chomp! $F = $LAST_READ_LINE.split if $F[5] == 'Suriname' && !($LAST_READ_LINE =~ \/^# \/)   $F.unshift $INPUT_LINE_NUMBER   print *$F end <\/code><\/pre>\n<p>  -n \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 \u0446\u0438\u043a\u043b while gets\u2026 end. \u0411\u043b\u043e\u043a BEGIN {\u2026 } \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0440\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u0434\u0435. \u0412\u044b\u0437\u043e\u0432 IO#print \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u0432 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0444\u0430\u0439\u043b, \u0430 -i \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b.<\/p>\n<p>  \u041d\u0430 \u0437\u0430\u043c\u0435\u0442\u043a\u0443: -p \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e\u0447\u0442\u0438 \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e -n, \u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 pring $_ \u0432 \u043a\u043e\u043d\u0435\u0446 \u0446\u0438\u043a\u043b\u0430. \u041e\u043d \u0447\u0438\u0442\u0430\u0435\u0442 \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0438\u0448\u0435\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0444\u0430\u0439\u043b\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0432\u0430\u043c \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0438\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0438 \u043f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0438\u0441\u044c\u044e.<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0446\u0438\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438<\/h4>\n<p>  <\/p>\n<pre><code class=\"ruby\">#!\/usr\/bin\/env ruby -w -n -i -F, -l require 'english' BEGIN {   $OUTPUT_FIELD_SEPARATOR  = ';' }  $F = $LAST_READ_LINE.split if $F[5] == 'Suriname' && !($LAST_READ_LINE =~ \/^# \/)   $F.unshift $INPUT_LINE_NUMBER   print *$F end <\/code><\/pre>\n<p>  -F \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f $INPUT_FIELD_SEPARATOR. -l \u0433\u043e\u0432\u043e\u0440\u0438\u0442 Ruby \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 $INPUT_RECORD_SEPARATOR \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 $OUTPUT_FIELD_SEPARATOR \u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c $INPUT_FIELD_SEPARATOR \u0438\u0437 $LAST_READ_LINE \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f String#chomp!.. \u0427\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442: \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0435\u043d \u0438\u0437 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a (\u0447\u0442\u043e \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u043d\u043e) \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043a \u0441\u0442\u0440\u043e\u043a\u0430\u043c \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c (\u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e, \u0447\u0435\u0433\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c).<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 -a:  <\/p>\n<pre><code class=\"ruby\">#!\/usr\/bin\/env ruby -w -n -i -F, -l -a require 'english' BEGIN {   $OUTPUT_FIELD_SEPARATOR  = ';' }  if $F[5] == 'Suriname' && !($LAST_READ_LINE =~ \/^# \/)   $F.unshift $INPUT_LINE_NUMBER   print *$F end <\/code><\/pre>\n<p>  \u0421 -a Ruby \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0437\u043e\u0431\u044c\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 $F \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438.  <\/p>\n<h4>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439<\/h4>\n<p>  \u0412 Ruby \u0435\u0441\u0442\u044c \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043e\u043f\u0446\u0438\u0435\u0439 -n \u0438\u043b\u0438 -p. \u0423\u0441\u043b\u043e\u0432\u0438\u044f, \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043a $LAST_READ_LINE, \u0430 \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u043a $INPUT_LINE_NUMBER. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 \u0437\u043d\u0430\u043d\u0438\u044e, \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440:  <\/p>\n<pre><code class=\"ruby\">#!\/usr\/bin\/env ruby -w -n -i -F, -l -a require 'english' BEGIN {   $OUTPUT_FIELD_SEPARATOR  = ';' }  unless $F[5] != 'Suriname' || \/^# \/   $F.unshift $INPUT_LINE_NUMBER   print *$F end <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0421\u043e\u043a\u0440\u0430\u0449\u0430\u0435\u043c \u043a\u043e\u0434<\/h4>\n<p>  \u0423\u0431\u0435\u0440\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 english, \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043d\u0430 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0438 \u0437\u0430\u043f\u0438\u0448\u0435\u043c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0432 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443.  <\/p>\n<pre><code class=\"ruby\">#!\/usr\/bin\/env ruby -w -n -i -F, -l -a BEGIN { $, = ';' } print $., *$F unless $F[5] != 'Suriname' || \/^# \/ <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0414\u0430, \u043c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043d\u0435\u0434\u043e\u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e Awk \u043d\u0430 Ruby. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 Awk, \u0442\u043e \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 Ruby \u043b\u0443\u0447\u0448\u0435, \u0442\u043e \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u0438\u043c \u043a\u043b\u044e\u0447\u0430\u043c \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u0430\u0441 \u0445\u043e\u0440\u043e\u0448\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  \u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"ruby\">ruby -wlani -F, -e &quot;BEGIN { $, = ';' }&quot; -e &quot;print $., *$F unless $F[5] != 'Suriname' || \/^# \/&quot; <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u043f\u0430\u0440\u0441\u0438\u0442\u044c YAML:<\/p>\n<pre><code class=\"ruby\">ruby -r yaml -e 'puts YAML.load(ARGF)[&quot;database&quot;]' config\/database.yml <\/code><\/pre>\n<p>  \u0418\u043d\u043e\u0433\u0434\u0430, \u043c\u0435\u0442\u043e\u0434\u044b Awk \u0438\u043b\u0438 Sed \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0443\u043c\u0435\u0441\u0442\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u041d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e-\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0438\u043b\u0438 \u0432\u0430\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043e\u0431\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430 Ruby, \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u043c \u044f\u0437\u044b\u043a\u0435. \u0412\u0441\u0435\u0433\u0434\u0430 \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438, \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c Ruby \u043c\u043e\u0436\u0435\u0442 \u0443\u0434\u0438\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e Ruby \u2014 \u044d\u0442\u043e \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442.<\/p>\n<h5>\u0421\u0441\u044b\u043b\u043a\u0438<\/h5>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/arjanvandergaag.nl\/blog\/using-ruby-command-line-options.html\">http:\/\/arjanvandergaag.nl\/blog\/using-ruby-command-line-options.html<\/a><\/li>\n<li><a href=\"http:\/\/arjanvandergaag.nl\/blog\/using-ruby-command-line-options.html\">https:\/\/speakerdeck.com\/avdgaag\/getting-started-with-ruby](https:\/\/speakerdeck.com\/avdgaag\/getting-started-with-ruby<\/a><\/li>\n<li><a href=\"http:\/\/arjanvandergaag.nl\/blog\/using-ruby-command-line-options.html\">http:\/\/ruby-doc.org\/stdlib-2.1.2\/libdoc\/optparse\/rdoc\/OptionParser.html<\/a><\/li>\n<li><a href=\"http:\/\/arjanvandergaag.nl\/blog\/using-ruby-command-line-options.html\">http:\/\/ruby-doc.org\/stdlib-2.0.0\/libdoc\/find\/rdoc\/Find.html<\/a><\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/229789\/\"> http:\/\/habrahabr.ru\/post\/229789\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       \u041c\u043d\u043e\u0433\u0438\u0435 \u043d\u0435 \u0437\u043d\u0430\u044e\u0442 \u043e \u0442\u0435\u0445 \u043c\u043e\u0449\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0447\u0442\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 Ruby. \u041e\u043d\u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043a\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e\u0435 \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u043e\u043a\u0430\u0437\u0430\u043b \u043d\u0430 \u044f\u0437\u044b\u043a Perl \u0438 \u0447\u0442\u043e Ruby \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0442\u0441\u0440\u0443\u043c\u0435\u043d\u0442 \u043e\u0431\u0449\u0435\u0433\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  \u041f\u0443\u0441\u0442\u044c \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0443 \u043d\u0430\u0441 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u0414\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043a\u0430\u043a CSV, \u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u043e \u0441\u0442\u0440\u0430\u043d\u0435. \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430:  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-229789","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/229789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229789"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/229789\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}