Best way to skip first line?

Reply

Join Date: Feb 2006
Posts: 17
Reputation: rusman is an unknown quantity at this point 
Solved Threads: 0
rusman rusman is offline Offline
Newbie Poster

Best way to skip first line?

 
0
  #1
Jun 6th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 148
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 39
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: Best way to skip first line?

 
0
  #2
Jun 7th, 2007
more +2 <file>
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Best way to skip first line?

 
0
  #3
Jun 14th, 2007
Or use sed
Are you Agile.. ?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 11
Reputation: vrgurav is an unknown quantity at this point 
Solved Threads: 1
vrgurav vrgurav is offline Offline
Newbie Poster

Re: Best way to skip first line?

 
0
  #4
Jun 19th, 2007
tail +n <filename>

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

Hope this will solve your query
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 11
Reputation: vrgurav is an unknown quantity at this point 
Solved Threads: 1
vrgurav vrgurav is offline Offline
Newbie Poster

Re: Best way to skip first line?

 
0
  #5
Jun 19th, 2007
Originally Posted by rusman View Post
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 17
Reputation: rusman is an unknown quantity at this point 
Solved Threads: 0
rusman rusman is offline Offline
Newbie Poster

Re: Best way to skip first line?

 
0
  #6
Jun 20th, 2007
Thanks all, I used more as that was the first response and it worked!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1
Reputation: dan_armstrong is an unknown quantity at this point 
Solved Threads: 0
dan_armstrong dan_armstrong is offline Offline
Newbie Poster

Re: Best way to skip first line?

 
0
  #7
Dec 10th, 2008
Here is what I did as the "fastest" way to skip the first line. Fastest=best for my situation.

Shell Scripting Syntax (Toggle Plain Text)
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <errno.h>
  4.  
  5. #define BUFFER_SIZE 4096
  6.  
  7. int main() {
  8. // Use block I/O
  9. char buff[BUFFER_SIZE];
  10. int firstLine = 1;
  11. size_t numRead;
  12. while((numRead = read(STDIN_FILENO, buff, BUFFER_SIZE))!=0) {
  13. if(numRead==-1) {
  14. perror("read");
  15. return 1;
  16. }
  17. size_t writePos = 0;
  18. // Skip first line
  19. if(firstLine) {
  20. while(writePos<numRead) {
  21. if(buff[writePos++]=='\n') {
  22. firstLine = 0;
  23. break;
  24. }
  25. }
  26. }
  27. while(writePos<numRead) {
  28. size_t numWritten = write(STDOUT_FILENO, buff+writePos, numRead-writePos);
  29. if(numWritten==-1) {
  30. perror("write");
  31. return 1;
  32. }
  33. writePos += numWritten;
  34. }
  35. }
  36. return 0;
  37. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Best way to skip first line?

 
0
  #8
Dec 10th, 2008
Hey there,

Did I miss:

sed 1d FILENAME
? Just checking

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC