Q:

Efficient way to read text files having irregular formats without using FOR loop in R

I have a input file that have the pattern as follow: 
- the first 2 lines contain parameters for the model & month & year: I only need to get month and year from these 2 lines
- the next block contains the actual data: 172 rows and 256 columns
The data goes on N times
Link to the actual data
Another file is an ArcGIS ascii grid which has the first 6 lines are ArcGIS parameters and a block of 172 rows x 256 columns (equal 1 inside the region, -9999 elsewhere)
Link to the ArcGIS ascii grid
What I'd like to do is to read the data and calculate average value for each timestep based on the mask grid. At the moment the only way I can think of is to use 3 nested loops 
for (i in 1:N) {
   for (j in 1:172) {
      for (k in 1:252) {
           Read the data
           Do calculation
           Write the result out
      }
   }
{

Is there any better way to avoid using such complicated FOR loop? Any suggestion would be greatly appreciated! 
Edit: based on what agstudy suggested and other sources, I read my data line-by-line and use strsplit to get the value. My final code is as follow
########################## Read the grid first ########################
con <- file(gisGrid) 
open(con);

# Read the first 6 lines
gisData <- readLines(textConnection(
'ncols         256
nrows         172
xllcorner     730000
yllcorner     227000
cellsize      1320
NODATA_value  -9999'),n=6)

# Extract value
gisPara <- matrix(unlist(strsplit(gisData,' +')), ncol=2, byrow=TRUE)
summary(gisPara)

# Read the mask grid:
gridValue <- read.table(file = gisGrid, header = FALSE, skip=6)
gridValueVec <- as.vector(as.matrix(gridValue))

close(con)

######################### Read the data file #########################
con <- file(dataFile) 
open(con);

# Define number of timesteps, nRow, nCol
nTime <- 3
nRow <- 172
nCol <- 256

# Read the whole file in
data.lines <- scan(con, what=character(), sep='\n')
data <- NULL
# Create 3D object to store data for each timestep
data$timestep <- list( rep( matrix(nrow=nRow, ncol=nCol), nTime ) )
data$month <- list( rep( nTime ) )
data$year <- list( rep( nTime ) )
data$multiply <- list( rep( nTime ) )

# Loop over all timestep
for (i in 1:nTime) {
  # Read the first 2 lines
  data.lines <- data.lines[-1] # remove line from the dataset

  data.line2 <- strsplit(data.lines[1],' ')
  data$month[[i]] <- data.line2[[1]][24]
  data$year[[i]] <- as.numeric(data.line2[[1]][25])
  data.lines <- data.lines[-1]

  dataRead <- matrix(nrow=nRow, ncol=nCol)
  for(j in 1:nRow) 
  {
    dataRead[j,] <- as.numeric(strsplit(data.lines[1],' ')[[1]])
    data.lines <- data.lines[-1]
  }         

  # Multiply data with the mask grid
  dataReadVector <- as.vector(dataRead)
  gridMultiplication <- ifelse(gridValueVec==-9999, NA,
                               dataReadVector * gridValueVec )

  data$multiply[[i]] <- mean(gridMultiplication, na.rm=TRUE)
  data$timestep[[i]] <- dataRead
}

close(con)

A:

For the first File you can use do the following:
Parse the date you read only 2 lines using readLines
dd <- readLines(
   textConnection('internal  1.0  (free)  -1                 Sep 1990'),n=2)
regmatches(dd,gregexpr('[A-Z][a-z]{2} [0-9]{4}$',dd))[[1]]
"Sep 1990" ## strsplit(...,' ') if you want month/and year separately

Then you read the matrix using something like :
 read.table(...,skip=2)

For the second File , you can use `strsplit to read the parameters in the file first 6 lines:
dd <- readLines(textConnection('ncols         256
nrows         172
xllcorner     730000
yllcorner     227000
cellsize      1320
NODATA_value  -9999
'),n=6)
matrix(unlist(strsplit(dd,' +')),ncol=2,byrow=TRUE)

    [,1]           [,2]    
[1,] "ncols"        "256"   
[2,] "nrows"        "172"   
[3,] "xllcorner"    "730000"
[4,] "yllcorner"    "227000"
[5,] "cellsize"     "1320"  
[6,] "NODATA_value" "-9999" 

