I have a text file that's over 100MB, each line of which has the same number of columns:Column No.: 0 1 2 3 4 5 6            d x c c s b c            .............I want to add , at given locations. For example, location = 2, 3, 5The desired output would be:Column No.:  0 1 2  3  4 5  6             d x c, c, s b, c             .............The location file would be a text or csv file235The text file has to have delimiters.Update:Sample dataNote: the line breaks are where I want to put delimitersColumn No. is the byte offset from the beginning of the line
How to insert comma at given location?
text processing;perl
Use Sed.Note that you won't be using 0 indexed positions, but starting from 1.  So I've incremented the numbers you gave.Also, you have to go back to front since once you change the first one, the column positions change.  So use Sed like so:sed 's/./&,/6;s/./&,/4;s/./&,/3'Example:$ echo dxccsbcdxccsbc$ echo dxccsbc | sed 's/./&,/6;s/./&,/4;s/./&,/3'dxc,c,sb,c$ The s command in Sed is for substitution.The pattern . matches any single character.The & in the replacement text means the text that was matched, and the comma is a literal comma.The numerical flag after the last / means to only perform the substitution on the nth match on the line.If you want to be really fancy, use Bash brace expansion to create the Sed commands:$ echo dxccsbc | sed '-es/./&,/'{6,4,3}dxc,c,sb,cBut that's just icing on the cake and probably confusing unless you understand both Sed and Bash quite well.  :)If you want to pull the list of positions from a separate file (as you actually show in your question), you can do this like so:sed -f <(sort -rn positionsfile | sed -n 's:^[1-9][0-9]*$:s/./\&,/&:p') fileNote this is Bash-specific as it uses process substitution syntax that is not POSIX.  Also note I've made this quite robust as anything but actual numbers in the positionsfile (that don't start with 0) will be discarded.Test results:$ cat file abcdefgABCDEFGabcdelaksjdflkjsdfllisdlfihsdlfkj$ cat positionsfile 21557something01not a number$ sed -f <(sort -rn positionsfile | sed -n 's:^[1-9][0-9]*$:s/./\&,/&:p') fileab,cde,fgAB,CDE,FGab,cde,laksjdflkj,sdfllisd,lfi,hsdlfkj$ 