I need to read in a list from a file, but I want to always ignore/skip the first line of this file.

Right now I'm just cat'ing the file and awk'ing the first column as that's all I need. However, this will also give me the first column of the first line which I do not want.

The first entry will probably be the same value everytime, so I could put a test in to skip that, but wondered if there was another quicker way and so that I'm not always testing every value.

Thanks!

more +2 <file>

Or use sed

tail +n <filename>

to start from second line
eg : tail +2 <filename>

Hope this will solve your query

I need to read in a list from a file, but I want to always ignore/skip the first line of this file.

Right now I'm just cat'ing the file and awk'ing the first column as that's all I need. However, this will also give me the first column of the first line which I do not want.

The first entry will probably be the same value everytime, so I could put a test in to skip that, but wondered if there was another quicker way and so that I'm not always testing every value.

Thanks!

tail +n filename

eg: tail +2 filename

Thanks all, I used more as that was the first response and it worked!!

Here is what I did as the "fastest" way to skip the first line. Fastest=best for my situation.

#include <unistd.h>
#include <stdio.h>
#include <errno.h>

#define BUFFER_SIZE 4096

int main() {
  // Use block I/O
  char buff[BUFFER_SIZE];
  int firstLine = 1;
  size_t numRead;
  while((numRead = read(STDIN_FILENO, buff, BUFFER_SIZE))!=0) {
    if(numRead==-1) {
      perror("read");
      return 1;
    }
    size_t writePos = 0;
    // Skip first line
    if(firstLine) {
      while(writePos<numRead) {
        if(buff[writePos++]=='\n') {
          firstLine = 0;
          break;
        }
      }
    }
    while(writePos<numRead) {
      size_t numWritten = write(STDOUT_FILENO, buff+writePos, numRead-writePos);
      if(numWritten==-1) {
        perror("write");
        return 1;
      }
      writePos += numWritten;
    }
  }
  return 0;
}

Hey there,

Did I miss:

sed 1d FILENAME

? Just checking :)

, Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.