AWK replacing tabs in last column with conditions -
i'm trying work dataset contains tabs delimiters, last column has custom field users able enter custom text, including tabs. i'm trying delete tabs using
awk "/\t/{c++;if(c==7){sub(\"\t\",\"\");c=0}}1" users10000.csv >users10000awk.csv
but seems there no delimiter between 6th , 7th column 7th empty.
what i'm trying replace tabs found after 7th if last field not empty through
awk /\t/{c++;if((c==7) && ($12!=\"\")){sub(\"\t\",\"\");c=0;}}1 usersorig.csv >usersorigawk.csv
but results in error
){sub(\"\t\" unexpected @ time.
i'm new awk , hoping work, formatting pain used to. chance help?
sample input:
100008949 esttrellitta 264 44 6853 0 28 dec 2009 18:01:42 gmt el paso,tx. 100009841 chelseabex 152 50 394 0 28 dec 2009 18:05:43 gmt 100012792 erinpattisonn 984 666 5003 0 28 dec 2009 18:19:39 gmt under bed. 100013967 tubeautifulrosa 323 251 1269 0 28 dec 2009 18:24:51 gmt on twitter ....... ahaahaa ! 100014135 geenajohnson 144 130 9789 0 28 dec 2009 18:25:37 gmt arkansas 100015928 goosau 93 286 8075 0 28 dec 2009 18:33:59 gmt 10001882 rjwilson 1 340 6358 0 6 nov 2007 15:54:47 gmt iphone: 39.053871, 95.674576 100019750 hovminajjackson 135 136 6022 0 28 dec 2009 18:51:29 gmt neverland 100020433 mattiebx 131 97 2610 0 28 dec 2009 18:54:40 gmt zundert 100024321 katiestepek 64 93 503 0 28 dec 2009 19:13:08 gmt hamilton 137179909 lalovesu 431 499 19568 0 26 apr 2010 01:45:05 gmt oakland,\ ca
the last line 1 of culprits want edit.
perhaps want?
$ seq 10 | paste -sd'\t' 1 2 3 4 5 6 7 8 9 10 $ seq 10 | paste -sd'\t' | sed 's/\t/ /7g' 1 2 3 4 5 6 7 8 9 10
i think gnu-sed supports though. note, d'\t'
default emphasize we're using tabs
update
to make work on tab delimited file row row
$ sed 's/\t/ /7g' input.file > output.file
Comments
Post a Comment