awk - Change character in only one column in a file -


i have file looks

0.9216  .   0 0.6774  .   1 0.7954  .   3 0.6375  .   1 0.6262  .   1 

and replace second column "." different character, "+".

i can using sed with:

sed 's/[.]/+/g'  

but "." in first column change plus signs. i've been thinking using awk might allow me apply syntax 1 column, haven't been able syntax right. suggestions? thank you!

edited add additional data: both of below solutions work abbreviated data above, neither works expanded data, looks this:

dm  g   0.874   1   358 440 12  126890980   .   0 dm  g   0.8253  0.9582  358 440 4   57561647    .   1 dm    0.5438  0.9531  358 440 4   85161551    na  1 dm  t   0.4991  0.8726  358 440 4   108826383   .   1 dm    0.7246  0.9817  358 440 4   114553253   .   1 dm  c   0.7691  0.9125  358 440 4   172776204   .   1 

why be? i've tried specifying spaces tabs, they're both tab delimited.

using sed: put spaces around segregate decimal points.

$ sed 's/ [.] / + /' file 0.9216  +   0 0.6774  +   1 0.7954  +   3 0.6375  +   1 0.6262  +   1 

using awk: though loose additional spaces when modify column, awk rebuilds line default ofs of space.

$ awk 'sub(/[.]/," + ",$2)' file 0.9216  +  0 0.6774  +  1 0.7954  +  3 0.6375  +  1 0.6262  +  1 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -