text: user4595: I have 200 .vcf files like this on a Linux system:
  #CHROM  POS ID  REF ALT
  chr4    5708160 .   G   GATAAC
  chr4    30280292    .   C   CACGTAT
  chr6    166253422   .   C   CCTTTCT
  chr11   21931340    .   A   AACACACGC
  chr12   118404422   .   G   GCACACA
  chr15   22672047    .   T   TAAGTAGATTTAAG
  chr16   32656293    .   ATGATT  A
  
  I want to modify my .vcf files in this way
  For instance if the reference allele in REF column is TCTC and alteration allele in ALT column is T, because T is the first common nucleotide in both reference and alteration so we remove T from ALT column so REF would remain as TCTC and ALT would be - . In total I mean removing whatever in ALT which is common with the first allele in REF.
  Any help please?
  This is what I got by @haci's code
  > head(var.annovar.maf2[1:6,1:13])
     Tumor_Sample_Barcode Chromosome Start_Position End_Position Reference_Allele Tumor_Seq_Allele2 Hugo_Symbol Variant_Classification
  1:                  new       chr1       89616151     89616151                G                 T        GBP7      Missense_Mutation
  2:                  new      chr16       20556547     20556547                C                 G      ACSM2B      Missense_Mutation
  3:                  new      chr17       66992092     66992092                C                 A       ABCA9      Missense_Mutation
  4:                  new      chr20       13251339     13251339                C                 T        ISM1                 Silent
  5:                  new       chr1          56987        56987               CA                 -           .                   <NA>
  6:                  new       chr1        4133415      4133415               AG                 -           .                   <NA>
               tx   exon txChange aaChange Variant_Type
  1:    NM_207398  exon6  c.C733A  p.L245I          SNP
  2: NM_001105069 exon10 c.G1213C  p.G405R          SNP
  3:    NM_080283 exon26 c.G3499T p.G1167C          SNP
  4:    NM_080826  exon2  c.C327T  p.N109N          SNP
  5:         <NA>   <NA>     <NA>     <NA>          DEL
  6:         <NA>   <NA>     <NA>     <NA>          DEL
  >
  
  
  user3541: I am pretty sure that there is a reason that the first nucleotide of the ALT is the same as that of REF in VCF files, however I was not able to find a reference for this.
  If you really need to do this for some reason, you will need to compare the alt and ref entries base by base starting from base 1 of each and until a mismatch. Here is some R code doing that:
  library(data.table)
  my_csv <- fread("example_vcf.txt")
  print(my_csv)
  
  # loop over each row
  for(i in 1:nrow(my_csv)) {
  
    # make "strings" from the ref and alt columns, make "arrays" of letters out of these strings
    ref <- as.character(my_csv[i, "REF"])
    ref_array <- unlist(strsplit(as.character(my_csv[i, "REF"]), split = ""))
  
    alt <- as.character(my_csv[i, "ALT"])
    alt_array <- unlist(strsplit(as.character(my_csv[i, "ALT"]), split = ""))
  
    # which of the ref alt-pair shorter and how long
    shortest <- c(nchar(ref), nchar(alt))[which.min(c(nchar(ref), nchar(alt)))]
  
    # compare ref and alt base by base, remove from alt if same nucleotide present in both, stop at first mismatch
    index <- 1
    new_alt <- alt_array
    while(index <= shortest) {
      if (ref_array[index] == alt_array[index]) {
        new_alt <- new_alt[-1]
      } else {
        break()
      }
      index <- index + 1
    }
  
    my_csv[i,"ALT"] <- paste(new_alt, collapse = "")
  
    # use "-" if alt is empty
    if (my_csv[i,"ALT"] == "") {
      my_csv[i,"ALT"] <- "-"
    }
  }
  
  print(my_csv)
  
  I have added some test cases at the end of the sample piece in your sample and the code is adding another column so that the changes made to the ALT are easier to see:
  > print(my_csv)
      #CHROM       POS ID    REF            ALT       NEW_ALT
   1:   chr4   5708160  .      G         GATAAC         ATAAC
   2:   chr4  30280292  .      C        CACGTAT        ACGTAT
   3:   chr6 166253422  .      C        CCTTTCT        CTTTCT
   4:  chr11  21931340  .      A      AACACACGC      ACACACGC
   5:  chr12 118404422  .      G        GCACACA        CACACA
   6:  chr15  22672047  .      T TAAGTAGATTTAAG AAGTAGATTTAAG
   7:  chr16  32656293  . ATGATT              A             -
   8: chrXXX       XXX  .   TCTC              T             -
   9: chrXXX       XXX  .   TCTC           TCTC             -
  10: chrXXX       XXX  .   TCTC             TA             A
  11: chrXXX       XXX  .   TCTC            TAT            AT
  
  
original_text: 4595: <p>I have 200 .vcf files like this on a Linux system:</p>
  
  <pre><code>#CHROM  POS ID  REF ALT
  chr4    5708160 .   G   GATAAC
  chr4    30280292    .   C   CACGTAT
  chr6    166253422   .   C   CCTTTCT
  chr11   21931340    .   A   AACACACGC
  chr12   118404422   .   G   GCACACA
  chr15   22672047    .   T   TAAGTAGATTTAAG
  chr16   32656293    .   ATGATT  A
  </code></pre>
  
  <p>I want to modify my .vcf files in this way</p>
  
  <p>For instance if the reference allele in <code>REF column</code> is <code>TCTC</code> and alteration allele in <code>ALT column</code> is <code>T</code>, because T is the first common nucleotide in both reference and alteration so we remove <code>T</code> from <code>ALT column</code> so REF would remain as <code>TCTC</code> and ALT would be <code>-</code> . In total I mean removing whatever in ALT which is common with the first allele in REF.</p>
  
  <p>Any help please?</p>
  
  <p>This is what I got by @haci's code</p>
  
  <pre><code>&gt; head(var.annovar.maf2[1:6,1:13])
     Tumor_Sample_Barcode Chromosome Start_Position End_Position Reference_Allele Tumor_Seq_Allele2 Hugo_Symbol Variant_Classification
  1:                  new       chr1       89616151     89616151                G                 T        GBP7      Missense_Mutation
  2:                  new      chr16       20556547     20556547                C                 G      ACSM2B      Missense_Mutation
  3:                  new      chr17       66992092     66992092                C                 A       ABCA9      Missense_Mutation
  4:                  new      chr20       13251339     13251339                C                 T        ISM1                 Silent
  5:                  new       chr1          56987        56987               CA                 -           .                   &lt;NA&gt;
  6:                  new       chr1        4133415      4133415               AG                 -           .                   &lt;NA&gt;
               tx   exon txChange aaChange Variant_Type
  1:    NM_207398  exon6  c.C733A  p.L245I          SNP
  2: NM_001105069 exon10 c.G1213C  p.G405R          SNP
  3:    NM_080283 exon26 c.G3499T p.G1167C          SNP
  4:    NM_080826  exon2  c.C327T  p.N109N          SNP
  5:         &lt;NA&gt;   &lt;NA&gt;     &lt;NA&gt;     &lt;NA&gt;          DEL
  6:         &lt;NA&gt;   &lt;NA&gt;     &lt;NA&gt;     &lt;NA&gt;          DEL
  &gt;
  </code></pre>
   3541: <p>I am pretty sure that there is a reason that the first nucleotide of the <code>ALT</code> is the same as that of <code>REF</code> in <code>VCF</code> files, however I was not able to find a reference for this.</p>
  
  <p>If you really need to do this for some reason, you will need to compare the alt and ref entries base by base starting from base 1 of each and until a mismatch. Here is some R code doing that:</p>
  
  <pre><code>library(data.table)
  my_csv &lt;- fread("example_vcf.txt")
  print(my_csv)
  
  # loop over each row
  for(i in 1:nrow(my_csv)) {
  
    # make "strings" from the ref and alt columns, make "arrays" of letters out of these strings
    ref &lt;- as.character(my_csv[i, "REF"])
    ref_array &lt;- unlist(strsplit(as.character(my_csv[i, "REF"]), split = ""))
  
    alt &lt;- as.character(my_csv[i, "ALT"])
    alt_array &lt;- unlist(strsplit(as.character(my_csv[i, "ALT"]), split = ""))
  
    # which of the ref alt-pair shorter and how long
    shortest &lt;- c(nchar(ref), nchar(alt))[which.min(c(nchar(ref), nchar(alt)))]
  
    # compare ref and alt base by base, remove from alt if same nucleotide present in both, stop at first mismatch
    index &lt;- 1
    new_alt &lt;- alt_array
    while(index &lt;= shortest) {
      if (ref_array[index] == alt_array[index]) {
        new_alt &lt;- new_alt[-1]
      } else {
        break()
      }
      index &lt;- index + 1
    }
  
    my_csv[i,"ALT"] &lt;- paste(new_alt, collapse = "")
  
    # use "-" if alt is empty
    if (my_csv[i,"ALT"] == "") {
      my_csv[i,"ALT"] &lt;- "-"
    }
  }
  
  print(my_csv)
  </code></pre>
  
  <p>I have added some test cases at the end of the sample piece in your sample and the code is adding another column so that the changes made to the <code>ALT</code> are easier to see:</p>
  
  <pre><code>&gt; print(my_csv)
      #CHROM       POS ID    REF            ALT       NEW_ALT
   1:   chr4   5708160  .      G         GATAAC         ATAAC
   2:   chr4  30280292  .      C        CACGTAT        ACGTAT
   3:   chr6 166253422  .      C        CCTTTCT        CTTTCT
   4:  chr11  21931340  .      A      AACACACGC      ACACACGC
   5:  chr12 118404422  .      G        GCACACA        CACACA
   6:  chr15  22672047  .      T TAAGTAGATTTAAG AAGTAGATTTAAG
   7:  chr16  32656293  . ATGATT              A             -
   8: chrXXX       XXX  .   TCTC              T             -
   9: chrXXX       XXX  .   TCTC           TCTC             -
  10: chrXXX       XXX  .   TCTC             TA             A
  11: chrXXX       XXX  .   TCTC            TAT            AT
  </code></pre>
  