This can be done with this, $ sed -e 's/,/;/g' -e 's/;/,/1' infile test1,test2;test3 test4,test5 test6,test7;test8;test9;test10 test11,test12;test13;test14 If you have GNU `sed`, you can also use, sed 's/,/;/2g' infile