Advertisement

08.26.2008 at 04:02AM PDT, ID: 23678009 | Points: 500
[x]
Attachment Details

INSERT HEADER INTO COLUMN 1 AND STRIP UNWANTED SUB HEADERS

Asked by philsivyer in Ruby Scripting Language

Hello
Below is a script which Gertone kindly sorted for me - however, I've noticed that if I use file extension.csv then I get many commas after column 1 - for example .
More Than Availability Over Time,,,,,, 08/08/2008 00:00,5,143,GB04QAP050TOP27,100,6
If I use file extension .txt then I get one comma after column1 then none thereafter - for example ..
More Than Availability Over Time, 08/08/2008 00:00      5  143 GB04QAP050TOP27 100 6

This causes me a problem when uploading into msaccess - any help much appreciated and source file attached - if required.

my_path = "U:\\Phil_Sivyer\\4_Availability\\mercury_files_received_daily\\"
# put the local filenames of theinput files here
file_lst =  ["08082008.txt", "09082008.txt"]

sink = File.open(my_path + "joined.txt", "w")
# loop over the array with all the filenames listed
file_lst.each do |fl|
  # open the file and access each single line
  waiting_for_header = 1
  first_header_line = "first line"
  File.open(my_path + fl, "r").each do |line|
    if line =~ /^$/ then
    elsif line =~ /^\d+\/\d+\/\d+/ then
        waiting_for_header = 1
       sink.write(first_header_line + ", " + line)
    elsif waiting_for_header == 1 then
        waiting_for_header = 0
        first_header_line = line.rstrip!
      end
   end
end
sink.close()Start Free Trial
Attachments:
 
txt file
 
[+][-]08.26.2008 at 05:48AM PDT, ID: 22313949

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.26.2008 at 05:58AM PDT, ID: 22314046

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.26.2008 at 06:49AM PDT, ID: 22314580

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.26.2008 at 07:15AM PDT, ID: 22314919

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.26.2008 at 07:49AM PDT, ID: 22315380

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.26.2008 at 12:51PM PDT, ID: 22318681

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.27.2008 at 03:14AM PDT, ID: 22323009

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.27.2008 at 07:05AM PDT, ID: 22324855

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.27.2008 at 07:22AM PDT, ID: 22325061

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628