p5wizard and PHV - your solutions both worked! Thank you very much for your persistence on this issue. Thanks again for everyone for contributing. I learned a lot, and that's probably the most valuable thing of all! Time to donate some $$ to this site! It was worth it!
Thank you for the suggestion! However, I see no change in the output file. TEST field and header still remain. Did I miss something?
$ more test3.csv
COMPANY,TRANS-TYPE,INVOICE,CUSTOMER,STATUS,GL-STATUS,BATCH-NBR,PROCESS-LEVEL,TRANS-DATE,GL-DATE,DESC,ORIG-AMT,TEST...
I wanted to thank everyone for their input. Your responses were amazing for this time of week and day. Thank you very, very much.
I think that I will have to resort to some variation of the printf command where I specifically detail each field and which separator to use, excluding the last one...
Feherke,
Not sure what you are asking. My version of awk? I am on AIX 5.3, IBM 9110-510.
Field is removed with no problem, just the pesky comma remains. Unfortunately, I need csv file for further processing, just not one on the last field ...
Any other ideas?
Sorry for the typing errors. Now, it seems, output looks same as input. No changes made. I'm puzzled ...
awk 'BEGIN{FS=",";OFS=","} ; {NF--; print}' test3.csv > test4.csv
COMPANY,TRANS-TYPE,INVOICE,CUSTOMER,STATUS,GL-STATUS,BATCH-NBR,PROCESS-LEVEL,TRANS-DATE,GL-DATE,DESC,ORIG-AMT,TEST...
Annihilannic,
Good eye! It ran, but now I've introduced another character after the comma I am trying to remove (along with the last header and field):
$ awk 'BEGIN{FS=",";OFS=","} ; {$NF--; print}' test3.csv > test4.csv...
It complains ...
syntax error The source line is 1.
The error context is
BEGIN{FS=",";OFS=","} ; >>> {NF=--; <<<
awk: The statement cannot be correctly parsed.
The source line is 1.
Thanks for the fast response!!!!
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...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.