Quote:
Originally Posted by
Don Cragun
The short answer is yes.
But, I'm not sure I understand your requirements. If you want help creating an awk script to perform this taks, please answer the following questions:
- Do you want input fields 2 and 4 to be removed from every input line?
- If the value in input field 1 is not a constant in each set of four input lines, what happens?
- Is that set skipped? If so, should an error be printed?
- Should the value from the first line in the set be printed?
- Should the value from the last line in the set be printed?
- If the value in input field 3 is not a constant in each set of four input lines, what happens?
- Is that set skipped? If so, should an error be printed?
- Should the value from the first line in the set be printed?
- Should the value from the last line in the set be printed?
- Is the number of fields a constant for a given input file?
Hi Don, thanks for taking the time. Below, are the answers to your questions:
1. Do you want input fields 2 and 4 to be removed from every input line?
Yes - they need to be removed
2. If the value in input field 1 is not a constant in each set of four input lines, what happens?
-Is that set skipped? If so, should an error be printed?
-Should the value from the first line in the set be printed?
-Should the value from the last line in the set be printed?
Basically, values in fields 1 and 3 will remain constant for every set of 4 lines. Hence for every group of four lines, I need the values in the first line for these fields.
3. If the value in input field 3 is not a constant in each set of four input lines, what happens?
-Is that set skipped? If so, should an error be printed?
-Should the value from the first line in the set be printed?
-Should the value from the last line in the set be printed?
As stated above... the values in input fields 1 and 3 will remain constant for every set of four lines
4.Is the number of fields a constant for a given input file?
Yes the number of fields is constant for a given input file.
The following is the code that I am working with right now - though it isnt working and does not have all the features I need
awk '{for(j=5;j<=NF;j++) {!(NR%4){sum+=$j}{printf("%04d ", sum/2)}} {print "\n"}}'
Thanks again!!