![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to read and compare multiple fields in a column at the same time | ahjiefreak | Shell Programming and Scripting | 1 | 06-19-2008 11:08 AM |
| Replace 3 fields with null in the file | vukkusila | Shell Programming and Scripting | 1 | 09-12-2007 01:10 AM |
| Combine a datafile with Master datafile, emergent! | onthetopo | Shell Programming and Scripting | 6 | 05-12-2007 06:36 AM |
| search and replace different fields | tungaw2004 | UNIX for Dummies Questions & Answers | 3 | 03-29-2007 03:16 AM |
| replace one section in a datafile | Paprika | Shell Programming and Scripting | 4 | 06-17-2005 08:48 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
How do I read/find/replace fields in a csv datafile?
hello.
I'm somewhat a novice here so please be patient. My stumbling block when loading csvs into ORACLE tables is this: I need to read a csv datafile, check several fields in each line, and if any of stated fields contain A ZERO only [instead of YYYYMONDD date field expected] then replace it with a null/blank character. I had a go at: cat <datafile> | awk ‘$5 == “0” { “ “ } END { print }'; cat <datafile> | awk ‘$8 == “0” { “ “ } END { print }'; ..etc.. ..alas it didn't work.. all advice/comments very much appreciated Steven. |
|
||||
|
thanks for the quick reply..
the csv's first two lines look like: Code:
13426,Williams,Robyn,Robyn,20031106,0,0,20080421,0,NASP39,Casual Sport & Recreation Ass,43.24,FACI,E,FASP,SUPP,SP,NASP35,20080421,0,100,FACI,V,FASP,SUPP,SP,0,0,Ms,FT,FT,SUB 15721,Clinton,Hilary,Hilary,20041101,hs0jo,poppy@aol.com,20080601,0,HSL236,Project Manager,56.76,700,A,700,ACAD,PB,V32636,20071207,20080731,0.36,700,V,HSEN,VLEC,FL,0,0,Dr,PT,FT,SUB thanks again.. Steven Last edited by Yogesh Sawant; 06-20-2008 at 04:54 AM.. Reason: added code tags |
|
||||
|
..an error is being returned when I try to run this either by itself or in a script - am I not running it right?
$ cat SLsTester_DataFile.csv | awk BEGIN{FS=OFS=","}{for(i=1;i<=NF;i++){if($i=="0"){$i=""}}}1' file; ..the error given reads: -bash: syntax error near unexpected token `(' your assistance is very much appreciated.. regards, Steven |
|
||||
|
Don't pipe the result of the cat command to the file. This is sufficient:
Code:
awk 'BEGIN{FS=OFS=","}{for(i=1;i<=NF;i++){if($i=="0"){$i=""}}}1' SLsTester_DataFile.csv
Code:
awk 'BEGIN{FS=OFS=","}{for(i=1;i<=NF;i++){if($i=="0"){$i=""}}}1' SLsTester_DataFile.csv > NewFile
|
|
||||
|
..its stilll not running Im afraid..
$ awk 'BEGIN{FS=OFS=","}{for(i=1;i<=NF;i++){if($i=="0"){$i=""}}}1' SLsTester_DataFile.csv > SLsOUtputFile.csv; awk: syntax error near line 1 awk: bailing out near line 1 /applmgr@fintest:~/finliveappl/su/11.5.0/payroll/gl $ ..I've also tried running it within a script but it errors the same... Thing is, as I have several date fields in each line ($5 $8 $9 $19 $20 $27) that may or may not need changing (exactly the same however, from zero to null), will this script simply swap ALL fields it finds with a zero only populated or will I need to specify field numbers? Apologies for the questions but this is good for me to learn.. ThanksInAdvance... Steven |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| solaris |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|