How to search and replace multiple number sequences in a file using bash -
i have file lots of lines this:
dog:7066469:182:0:0:7050964:7087402:7058396:7079290:7087537 cat:7066469:182:0:0:7050964:7087402:7058396 dog:7066469:182:0:0:7050964:7087402:7058396:7079290
using bash programming (sed or awk or something), how can add 6 in front of every number after 5th ":", lines begins "cat:"? correct result this:
dog:7066469:182:0:0:7050964:7087402:7058396:7079290:7087537 cat:7066469:182:0:0:67050964:67087402:67058396 dog:7066469:182:0:0:7050964:7087402:7058396:7079290
using awk:
awk 'begin{fs=ofs=":"} $1=="cat"{for (i=6; i<=nf; i++) $i = "6" $i} 1' file dog:7066469:182:0:0:7050964:7087402:7058396:7079290:7087537 cat:7066469:182:0:0:67050964:67087402:67058396 dog:7066469:182:0:0:7050964:7087402:7058396:7079290
Comments
Post a Comment