to change only the second match word ( to replace Allow,Deny with Deny,Allow )
sed solution:
Sample tmp_file
:
Allow,Deny
Allow,Deny
Allow,Deny
Allow,Deny
sed ':a;N;$!ba; s/Allow,Deny/Deny,Allow/2' tmp_file
The output:
Allow,Deny
Deny,Allow
Allow,Deny
Allow,Deny
using awk
:
awk '/Allow/{c++; if (c==2) { sub("Allow","Deny")}}1'
match Allow
then keep a counter c
. If this matches the 2
second occurrence then we substitute it.