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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -