Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk file with extra character in output... 1

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I use awk scripts to help automate a data import routine into a MySQL database. The data is formatted incorrectly for the database and the following script is used for conversion (running on a hosted BSD server...)
Code:
BEGIN{FS=",";OFS=",";
           }
      
NR > 1 {
                    $9=tolower($9);
                    gsub("  work","",$9);
                    gsub("  home","",$9);
                    gsub("  other","",$9);
                    gsub("\"","");
                    gsub("\ 0:00:00","");
                    gsub("-","",$7);
                    gsub("-","",$8);
                    gsub(/[\177-\377]/, "");
                    
                    ro_date="";
                    if ($14 !="")
                      {
                       z=split($14,dt,"/");
                       year= dt[3];
                       month= dt[1];
                       day= dt[2]
                       ro_date = year"/"month"/"day;
                       }

            if($1 !="") {
       print $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, ro_date ; } }

The ro_date output returns and extra character string... A "^M", like this: 2009^M/7/6 which I assume is an end-of-line marker in the original data; but, I don't know how to resolve this in my output.

Any suggestion would be most appreciated,

TIA,

-A
 
Replace this:
NR > 1 {
with this:
NR > 1 {gsub(/\r/,"")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top