perl - replace every nth (and multiples) occurrences of a character with another character

后端 未结 6 998
余生分开走
余生分开走 2021-01-20 19:27

Does anyone know any unix commands/perl script that would insert a specific character (that can be entered as either hex (ie 7C) or as the actual character (ie |)) in the po

6条回答
  •  长发绾君心
    2021-01-20 20:07

    I have an idea in bash script :

    perl -pe 's/,/(++$n % 3 == 0) ? "|" : $&/ge'  data.txt
    

    That will do the trick.

提交回复
热议问题