Remove header in .csv file

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Remove header in .csv file

  • Creator
    Topic
  • #51844
    Huy Tran
    Participant

    I have .csv file coming into the engine. I’m looking for a script that removes the header (first line) of the file. Please share the script if you’ve done this before…

    Thanks in advance.

Viewing 2 reply threads
  • Author
    Replies
    • #71962
      Jim Kosloskey
      Participant

      Huy,

      I have not done this inside the engine.

      I do have a script that builds Cloverleaf Tables from delimited files and that has a provision for removing headers.

      However, one way I would attack this, off of the top of my head, is to use the DirParse UPoC and have Tcl code there that will take the file name from the list then read that file and create a new file (same name same location??) without the first line. If I wrote this proc I would give it an argument that specifies how many leading records are to be treated as header records. This is because some tools can xport multiple records as headers not just one.

      Then return the file list to Cloverleaf and it will now read the file without the first line.

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #71963
      Vaughn Skinner
      Participant

      If in unix, you can use a shell script that looks something like:

      sed -e 1d out

      In tcl, you can split by n (or whatever eol character) and remove the first item from the list and then join.

      set in “anbncn”

      set lines [split $in “n”]

      set lines [lreplace $lines 0 0]

      set out [join $lines “n”]

      puts $out

      I hope this helps.

    • #71964
      Charlie Bursell
      Participant

      Simple in an IB Tcl proc

      Assumes records are NL delimited

      # in starup or namespace (preferable)

      package require csv

      keylget args MSGID mh

      set IBLST [split [msgget $mh] n]

      # Remove first (header) record

      lvarpop IBLST

      # Now if you want to process the records

      foreach rec $IBLST

          set fields [csv::split $rec]

         # Now you have a list of fields, do what you will

      }

Viewing 2 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,292
Replies
34,432
Topic Tags
286
Empty Topic Tags
10