shell - Replacing pattern with pattern+incrementing number -
here snippet of text files want edit:
"> record:w7_s7_l001_r2_001_43549049:wang1141_nem_0425_6 aggctcgaacttcctttggatgaactccaaaagtccctctaagaagttaacaccttacaa "> record:w41_s41_l001_r2_001_36873913:wang1141_nem_0425_6 tgcctcaaacttccgtggattaaacatccacagtccctctaagaagttagccgtcaaccaa "> record:w32_s56_l001_r2_001_29095773:wang1141_nem_0425_6 tgcctcaaacttccttatgcttgcacataaagtccctctaagaagttagactccctattta
now want replace every ">" ">$a" , incrementing "$a++". found solution worked:
>awk '/>/{sub(/start/,++n);{print}'
but replaces > number without >.
i appreciate every help!
it's hard believe glance @ man page , maybe quick google couldn't figure out how fix code snippet had found want here is:
$ awk '/>/{sub(/>/,">"++n)}{print}' file ">1 record:w7_s7_l001_r2_001_43549049:wang1141_nem_0425_6 aggctcgaacttcctttggatgaactccaaaagtccctctaagaagttaacaccttacaa ">2 record:w41_s41_l001_r2_001_36873913:wang1141_nem_0425_6 tgcctcaaacttccgtggattaaacatccacagtccctctaagaagttagccgtcaaccaa ">3 record:w32_s56_l001_r2_001_29095773:wang1141_nem_0425_6 tgcctcaaacttccttatgcttgcacataaagtccctctaagaagttagactccctattta
get book effective awk programming, 4th edition, arnold robbins.
Comments
Post a Comment