I am having a text file which contains 1500 lines and I need to cut every third line starting from 1st line .In my file there is no header or footer. We can do this by reading it line by line, and count three before you actually do anything with the lines. You need to read the file line by line, and discard every line that is not a multiple of three. In general, the way you do this is by writing the lines you want to keep to a new file, so that when you're done, it will contain every third line of the first file. Here is pseudocode that you should be able to adapt into Perl: pseudocode Syntax inFile = open("SourceFile") outfile = open("DestinationFile") linecount = 0 while(inFile.containsMoreLines()) { increment lineCount textLine = inFile.readLine() if((lineCount mod 3) equals 0) outFile.writeLine(textLine) } inFile.close() outFile.close() If you are using Linux, we can simply do this by the command given below. awk 'NR%3==0' FILENAME where FILENAME is the name of your data file. You can replace 3 with N and get the Nth line as well.
Earthlink
Netscape
Netvouz
RawSugar
Shadows
Sphinn
StumbleUpon
Yahoo MyWeb
|
Post a Comment