I want to replace every 2nd occurance of a string/character from a line.
ababacbsbddbsbbcbdbssb
i want to replace every s2nd b with @ like below
should be like
aba@acbs@ddbs@bc@dbss@
I want to replace every 2nd occurance of a string/character from a line.
ababacbsbddbsbbcbdbssb
i want to replace every s2nd b with @ like below
should be like
aba@acbs@ddbs@bc@dbss@
what you tried so far ?
awk '/b/{c++;if(c%2=0){sub("b","@");c=0}}1' file1 > file2
suppose the string is present in the file1 and write to file2
echo "ababacbsbddbsbbcbdbssb" | nawk -Fb '{for(i=1;i<=NF;i++){if(i%2==1){printf("%sb",$i)}else{printf("%s@",$i)}}}'