shell - Remove alphanum,num,email and other special char from the 6th field of a file -


my city field ie 6th field has got addr,door #, email addr , special char in it,which getting job harder.i wanted replace numbers, email id,special char , other address city field of file blank space. want valid city names in there. tried awk awk -f'|' '$6 ~ /^[ ]*[0-9]{5}[ ]*$/', not getting me want. can me in advising soln or tell me i'm going wrong.i'm great have participation here.sorry making page convoluted

my data like:

name,age,loc,num,st,city,postal,sal,year,status1,status2,status3,s4

garry",30",us",7373",ny",newyork",7900",100",2010",0",0",0",0 raj",40",in",1291",in",newdelhi",8790",100",2012",1",1",1",1 kris",24",us",6328",nj",9012 cain street",8739",200",2012",0",1",1",1 romy",57",it",5623",oh",1900 obama st #4",3434",200",2013",1",1",1",1 tim",70",us",4004",ca",#205",9898",900",2017",1",1",1",1 steve",40",us",5656",wa",steveran@gmail.com",9123",289",2012",0",0",0",0 donald",34",us",3902",ca",donal@gmail.com",1290",300",2010",0",0",0",0 jaby",23",us",7800",wa",100-120",2900",100",2014",1",1",1",1 koay",25",us",8900",ca",apt. p120",1000",100",2011",1",0",1",1 james",30",us",3499",in",b290",8900",200",2019",0",1",",1 jake",29",us",5609",ma",3091",4901",200",2019",1",1",1",0 jon",40",us",3490",ih",2901 jakestall st 198",6790",100",0",0",",0",0 wayne",34",us",2679",wa",washington",349",9",9",9",9",9",9 

output has be: name,age,loc,num,st,city,postal,sal,year,status1,status2,status3,st4

garry",30",us",7373",ny",newyork",7900",100",2010",0",0",0",0 raj",40",in",1291",in",newdelhi",8790",100",2012",1",1",1",1 kris",24",us",6328",nj",",8739",200",2012",0",1",1",1 romy",57",it",5623",oh",",3434",200",2013",1",1",1",1 tim",70",us",4004",ca",",9898",900",2017",1",1",1",1 steve",40",us",5656",wa",",9123",289",2012",0",0",0",0 donald",34",us",3902",ca",",1290",300",2010",0",0",0",0 jaby",23",us",7800",wa",",2900",100",2014",1",1",1",1 koay",25",us",8900",ca",",1000",100",2011",1",0",1",1 james",30",us",3499",in",",8900",200",2019",0",1",",1 jake",29",us",5609",ma",",4901",200",2019",1",1",1",0 jon",40",us",3490",ih",",6790",100",0",0",",0",0 wayne",34",us",2679",wa",washington",349",9",9",9",9",9",9 

awk solution:

$ awk 'begin{fs=ofs=","} {$6=substr($6,1,length($6)-1);if ($6~/[^[:alpha:][:blank:]]/) $6=""}1' input.txt 

breakdown:

begin{fs=ofs=","}                         # input , output field separator "," { $6 = substr($6,1,length($6)-1);         # rid of trailing " in column 6   if ($6  ~ /[^[:alpha:][:blank:]]/)      # if col 6 contains char that's                                            #   not alphabetic or space      $6=""                                # empty col 6 }1                                        # print every line 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -