sed - Regex to replace a character if is unique -


i need please script regex fix big text file under linux (with sed example). records looks like:

1373350|doe, john|john|doe|||b|acme corp|... 1323350|simpson, homer|homer|simpson|||3|moe corp|... 

i need validate if 7th column has unique character (maybe letter or number) , if true, add second column without comma, mean:

1373350|doe, john|john|doe|||b doe john|acme corp|... 1323350|simpson, homer|homer|simpson|||3 simpson homer|moe corp|... 

any help? thanks!

awk better suited job:

awk -f '|' 'begin { ofs = fs } length($7) == 1 { x = $2; sub(/,/, "", x); $7 = $7 " " x } 1' filename 

that is:

begin { ofs = fs }   # output separated same way input length($7) == 1 {    # if 7th field 1 character long   x = $2             # make copy of second field   sub(/,/, "", x)    # remove comma   $7 = $7 " " x      # append seventh field } 1                    # print line 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -