Extracting certain lines from a text and outputting to new text files?
Dear forum,
I know about the awk command but I am having a hard time putting it to use on a text file I have. This text file has the following format: Quote:
Text file 1 for Test 1 scores Quote:
Quote:
Is there a way to do this using just awk or is there something else that would be needed? Can awk do sequence extraction... not sure if that's the right wording, what I mean is that every nth line is output (line 1, 6, 11, 16... to text file 1; lines 2, 7, 12, 17... to text file 2, etc.) rather than searching for value 2 in the second column and outputting those that match to text file 2. Hope this made some sense.. Thanks for your help! =) |
Hi and welcome to LinuxQuestions!
Checking the value in the second field would be the most straightforward method, anyway here we go: Code:
BEGIN { |
Thank you very much for your help colucix!
|
Here's another take on solving this "data distribution" problem.
This code assumes your input file has a name of the form "/home/daniel/Desktop/LQfiles/dbm266inp.txt" The script file is dbm266.bin and the input file is dbm266inp.txt. Use your own path name and program name but the "inp.txt" is important. Most of the code (below) is setup and comments. The real work is all on one line, the awk. Code:
# Daniel B. Martin Mar12 |
Here is the same idea:
Code:
awk 'NR > 1{print > $2".txt"}' file |
All times are GMT -5. The time now is 02:27 AM. |