title: use R to remove header (6 lines) from .asc file (ESRI ascii grid) and export
body: <p>I have over 800 .asc files (ESRI ascii grids) that each have a header consisting of 6 lines, then the raster data separated by spaces. Here is a small file as an example. I read it in using read.asciigrid (sp package).</p>
  
  <blockquote>
    <p>new("SpatialGridDataFrame"
        , data = structure(list(mydata.asc = c(4, 4, 4, 4, 3, 4, 4, 4, 1, 1, 1,  1, 1, 4, 4, 4, 4, 3, 4, 4, 4, 1, 1, 1, 1, 1, 4, 4, 4, 4, 3, 4, 
    4, 4, 1, 1, 1, 1, 1, 4, 4, 4, 4, 3, 4, 4, 4, 6, 1, 1, 1, 1, 4,  4, 4,
    4, 3, 4, 4, 4, 6, 1, 1, 1, 1, 4, 4, 4, 4, 3, 4, 4, 4, 6,  1, 1, 1, 1,
    4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 1, 1, 1, 4, 4, 4, 4,  4, 4, 4, 4, 6, 6,
    1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1,  1, 4, 4, 4, 4, 4, 4, 4,
    4, 4, 4, 6, 6, 6, 4, 4, 4, 4, 4, 4, 4,  4, 4, 4, 4, 4, 6)), .Names =
    "mydata.asc", row.names = c(NA, 
    -143L), class = "data.frame")
        , grid = new("GridTopology"
        , cellcentre.offset = c(394984.42630274, 2671265.4912109)
        , cellsize = c(25, 25)
        , cells.dim = c(13L, 11L) )
        , bbox = structure(c(394971.92630274, 2671252.9912109, 395296.92630274, 
    2671527.9912109), .Dim = c(2L, 2L), .Dimnames = list(NULL, c("min",  "max")))
        , proj4string = new("CRS"
        , projargs = NA_character_ ) )</p>
  </blockquote>
  
  <p>Here is what the file looks like if you view it with a text editor.</p>
  
  <p><img src="https://i.stack.imgur.com/N3x78.png" alt="enter image description here"></p>
  
  <p>Here are the steps I would like to do</p>
  
  <p>1) read in file
  2) remove first 6 lines (header)
  3) save file back out as .asc file with the same filename but in a different location</p>
  
  <p>Of course, I'd like to do this to 800 files, but if I can figure out how to do this for one file, I should be able to write a function to loop through all files.</p>
  
  <p>Thanks for any help.</p>
  
  <p>-al</p>
  
  <p>UPDATE:
  This is the final code that worked for me, thanks to @Luca Braglia.</p>
  
  <p>Set working directory</p>
  
  <pre><code>setwd("c:/temp/hdr/ascii")
  newdir &lt;- "c:/temp/hdr/ascii_no_hdr/"
  
  files &lt;- dir(pattern="*.asc")
  
  for (my.file in files){
    i &lt;- read.table(my.file,skip=6,sep="")
    write.table(i,file=paste(newdir,my.file,sep=""),sep="",row.names=FALSE,col.names=FALSE)
  }
  </code></pre>
  
  <p>I didn't want the col and row names. A very simple and effective piece of code.</p>