learningawk
Technical User
I'm having a slight problem with reformatting a data file.
Here's the input:
624 1010
0 4917
50 4921
100 4924
624 1042
0 4917
50 4921
100 4921
150 4924
624 1074
0 4895
50 4898
100 4901
150 4901
200 4904
and here's the script I've been using to group data together:
{
test1=substr($0,1,5);
if (match( test1, "[0-9]" )) {f1=substr($0,1,5); f2=substr($0,10,6)}
if (match( test1, "^[ ]*$" )) {f3=substr($0,10,8); f4=substr($0,20,8)}
print f1,f2,f3,f4
}
and here's the output that I get:
624 1010
624 1010 0 4917
624 1010 50 4921
624 1010 100 4924
624 1042 100 4924
624 1042 0 4917
624 1042 50 4921
624 1042 100 4921
624 1042 150 4924
624 1074 150 4924
624 1074 0 4895
624 1074 50 4898
624 1074 100 4901
624 1074 150 4901
624 1074 200 4904
You can notice the output is off on the first record and then the following records are off.
I would like to:
1. Correct this problem so it prints all 4 correct fields on the same line.
and also I would like to change script to a different ouput which would:
2. Change the output so that it only print the f1 and f2 on only the first group of records like this:
624 1010 0 4917
50 4921
100 4924
624 1042 0 4917
50 4921
100 4921
150 4924
624 1074 0 4895
50 4898
100 4901
150 4901
200 4904
Thanks alot for helping.
Here's the input:
624 1010
0 4917
50 4921
100 4924
624 1042
0 4917
50 4921
100 4921
150 4924
624 1074
0 4895
50 4898
100 4901
150 4901
200 4904
and here's the script I've been using to group data together:
{
test1=substr($0,1,5);
if (match( test1, "[0-9]" )) {f1=substr($0,1,5); f2=substr($0,10,6)}
if (match( test1, "^[ ]*$" )) {f3=substr($0,10,8); f4=substr($0,20,8)}
print f1,f2,f3,f4
}
and here's the output that I get:
624 1010
624 1010 0 4917
624 1010 50 4921
624 1010 100 4924
624 1042 100 4924
624 1042 0 4917
624 1042 50 4921
624 1042 100 4921
624 1042 150 4924
624 1074 150 4924
624 1074 0 4895
624 1074 50 4898
624 1074 100 4901
624 1074 150 4901
624 1074 200 4904
You can notice the output is off on the first record and then the following records are off.
I would like to:
1. Correct this problem so it prints all 4 correct fields on the same line.
and also I would like to change script to a different ouput which would:
2. Change the output so that it only print the f1 and f2 on only the first group of records like this:
624 1010 0 4917
50 4921
100 4924
624 1042 0 4917
50 4921
100 4921
150 4924
624 1074 0 4895
50 4898
100 4901
150 4901
200 4904
Thanks alot for helping.