i have some data files, and i need to pull some info out. i’d like to use a single awk script to get data out, so i can suck some data into bash arrays.
for this, let’s assume i need the following (1-indexed):
– i need awk to print column one on lines 2, 3, and 4
– i need awk to print columns 1, 2, and 3 on lines 8 and over. but i want all of the column ones printed before the column twos, and the column twos before the column threes.
using the following data example:
abc
def
ghi
jkl
mno
1a1
2b2
11 22 33 44
55 66 77 88
99 00 12 13
14 15 16 17
i would want awk to print the string:
def ghi jkl 11 55 99 14 22 66 00 15 33 77 12 16
i created the following, which i thought would work, but i am getting an error saying “END bocks must have an action part”.
awk '
BEGIN {i=0;}
{
if ((NR >= 2) && (NR <= 4))
print $1;
if (NR >= 8)
{
col1_arr[i] = $1;
col2_arr[i] = $2;
col3_arr[i] = $3;
i++;
}
}
END
{
for (j = 0; j < i; j++)
print col1_arr[j];
for (j = 0; j < i; j++)
print col2_arr[j];
for (j = 0; j < i; j++)
print col3_arr[j];
}' /path/to/my/file
thanks ahead of time.
This should work –