Guys, I would appreciate any help using awk or perl with the problem that I have.
I have file in following format;
1111 2222 1
3333 4444 2
5555 6666 3
7777 8888 1
9999 0000 3
1122 2233 1
3344 4455 2
5566 6677 2
7788 8899 2
9900 0011 3
and so on, the problem lies in column number 3 where data is segmented. The start of the data segment is represented by number 1 in the 3rd column and the end of the data segment is signified by number 3 in the 3rd column where as number 2 in the third column means the intermediate points between the start (1) and end (3). I have tried to represent all possible kinds that I can encounter. In simple words, I need the output to be as follows;
1111 2222 1
3333 4444 2
5555 6666 3
7777 8888 4
9999 0000 5
1122 2233 6
3344 4455 7
5566 6677 8
7788 8899 9
9900 0011 10
I would appreciate any help on this issue.
Try with this:
cat input.txt | awk '{printf "%s %s %s\n",$1,$2, NR}'
Ok sorry guys, my mistake, I did not format my question properly, here the input again (same, no change)
1111 2222 1
3333 4444 2
5555 6666 3
7777 8888 1
9999 0000 3
1122 2233 1
3344 4455 2
5566 6677 2
7788 8899 2
9900 0011 3
and here is the output i want (changed from last post as I did a mistake explaining what I want, essentially everytime we get 1 in the third column, it signifies the start of a new number and it continues until we get 3 and then again from the 1 following the number 3, we start the new counter)
1111 2222 1
3333 4444 1
5555 6666 1
7777 8888 2
9999 0000 2
1122 2233 3
3344 4455 3
5566 6677 3
7788 8899 3
9900 0011 3
hope it is clear now how I want to format.
awk '$3==1{++c}{$3=c}1' file
Franklin52, you have helped me before a lot too and now again it is your answer that works perfectly for me. Thanks my friend. Regards and godbless
my $n=1;
while(<DATA>){
my @tmp = split;
print join " ", @tmp[0..$#tmp-1];
print " $n\n";
if($tmp[2] eq 3){
$n+=1;
}
}
__DATA__
1111 2222 1
3333 4444 2
5555 6666 3
7777 8888 1
9999 0000 3
1122 2233 1
3344 4455 2
5566 6677 2
7788 8899 2
9900 0011 3