I'm totally new at this, so maybe, hopefully, this is an easy one.
I have a file which I want to remvoe the last field and header, keeping the OFS=","
When I execute the command, the last field and header are removed, but what is left is a comma (,) at the end. I am expecting nothing.
my file is:
COMPANY,TRANS-TYPE,INVOICE,CUSTOMER,STATUS,GL-STATUS,BATCH-NBR,PROCESS-LEVEL,TRA
NS-DATE,GL-DATE,DESC,ORIG-AMT,TEST
"30","C","123","ABC","1","2","1","ACTUL","20070228","20070228","ACTUAL CLAIMS UP
LOAD","12.00","TEST"
"30","C","123","ABC","1","2","1","ACTUL","20070228","20070228","ACTUAL CLAIMS UP
LOAD","-12.00","TEST"
I run: awk 'BEGIN{FS=" ";OFS=","} ; {$NF="";print}' test3.csv > test4.csv
and get
COMPANY,TRANS-TYPE,INVOICE,CUSTOMER,STATUS,GL-STATUS,BATCH-NBR,PROCESS-LEVEL,TRA
NS-DATE,GL-DATE,DESC,ORIG-AMT,
"30","C","123","ABC","1","2","1","ACTUL","20070228","20070228","ACTUAL CLAIMS UP
LOAD","12.00",
"30","C","123","ABC","1","2","1","ACTUL","20070228","20070228","ACTUAL CLAIMS UP
LOAD","-12.00",
with vi I see that there is a space there at the end, so I ran
awk '{sub(/[\t]+$/,"");print}' test4.csv > test5.csv
but it doesn't remove the last comma or space after it.
I also ran commands to remove leading spaces, removing sapces within, all to no avail ... what gives? What am I missing?
Thanks for your patience and help.
I have a file which I want to remvoe the last field and header, keeping the OFS=","
When I execute the command, the last field and header are removed, but what is left is a comma (,) at the end. I am expecting nothing.
my file is:
COMPANY,TRANS-TYPE,INVOICE,CUSTOMER,STATUS,GL-STATUS,BATCH-NBR,PROCESS-LEVEL,TRA
NS-DATE,GL-DATE,DESC,ORIG-AMT,TEST
"30","C","123","ABC","1","2","1","ACTUL","20070228","20070228","ACTUAL CLAIMS UP
LOAD","12.00","TEST"
"30","C","123","ABC","1","2","1","ACTUL","20070228","20070228","ACTUAL CLAIMS UP
LOAD","-12.00","TEST"
I run: awk 'BEGIN{FS=" ";OFS=","} ; {$NF="";print}' test3.csv > test4.csv
and get
COMPANY,TRANS-TYPE,INVOICE,CUSTOMER,STATUS,GL-STATUS,BATCH-NBR,PROCESS-LEVEL,TRA
NS-DATE,GL-DATE,DESC,ORIG-AMT,
"30","C","123","ABC","1","2","1","ACTUL","20070228","20070228","ACTUAL CLAIMS UP
LOAD","12.00",
"30","C","123","ABC","1","2","1","ACTUL","20070228","20070228","ACTUAL CLAIMS UP
LOAD","-12.00",
with vi I see that there is a space there at the end, so I ran
awk '{sub(/[\t]+$/,"");print}' test4.csv > test5.csv
but it doesn't remove the last comma or space after it.
I also ran commands to remove leading spaces, removing sapces within, all to no avail ... what gives? What am I missing?
Thanks for your patience and help.