Comments on: Replace every Nth occurrence https://backreference.org/2012/08/22/replace-every-nth-occurrence/ Proudly uncool and out of fashion Sun, 18 Jan 2015 18:35:49 +0000 hourly 1 https://wordpress.org/?v=5.8.2 By: waldner https://backreference.org/2012/08/22/replace-every-nth-occurrence/#comment-25169 Sun, 18 Jan 2015 18:35:49 +0000 http://backreference.org/?p=2928#comment-25169 In reply to aseel.

Using the perl example, assuming you want to replace every fourth "foo" with "bar":

perl -e '$count = 0; s/foo/(++$count % 4 == 0)?"bar":$&/ge;' inputfile.txt > outputfile.txt
]]>
By: aseel https://backreference.org/2012/08/22/replace-every-nth-occurrence/#comment-25167 Fri, 16 Jan 2015 16:14:55 +0000 http://backreference.org/?p=2928#comment-25167 Hi I'm new to using linux and I want to implement this tutorial to replace every 4th entry of a text. where do we put in the input file name and how do we get it to print the results in a different output file.

Thanks

]]>