Ruby

Ruby is a general purpose programming language.

Receive data in stdin from pipe

   1 #!/usr/bin/ruby
   2 # cat records.txt | ruby processrec.rb
   3 startRec=false
   4 endRec=false
   5 records=[]
   6 STARTREC="START\n"
   7 ENDREC="END\n"
   8 EMPTY=""
   9 
  10 ARGF.each do |line|
  11 
  12   if line.end_with?(STARTREC)
  13     startRec=true
  14   end
  15 
  16   if line.end_with?(ENDREC)
  17     endRec=true
  18   end
  19 
  20   if startRec and endRec==false and line.end_with?(STARTREC)==false and  line.end_with?(ENDREC)==false
  21     records.push(line.gsub(/\n/,EMPTY) )
  22   end
  23 
  24   if startRec and endRec
  25     out=EMPTY
  26 
  27     records.each do |item|
  28       out = "#{out} #{item}"
  29     end
  30 
  31     puts out
  32     startRec=false
  33     endRec=false
  34     records=[]
  35   end
  36 end

Ruby (last edited 2023-06-02 15:55:19 by 127)