I am trying to look for two characters, based on the characters I want to find the remaining fields values in its subsequent line
123456Baadvvdwhbdwbdhw test1 test2 test3 test4 test5
test1 here is the test.
test2 here is the test.
here is line to skip.
here is another line to skip.
test3 here is the test.
here is another line to skip.
123415341636b121313131 test1 test2 test3 test4 test5
here is another line to skip...
here is test5 found.
condition 1st: Check if 1st field has B(until next b OR B found) then look from 2nd field on-wards if their values are present in its subsequent lines, if they are present then print them(print first line B one if at least 1 match is found)
condition 2nd: Check if 1st field has b then look for last field in all subsequent lines(until next b OR B found in both conditions), print line having b if at least 1 subsequent line has found last field as a match in it.
expected output for above shown samples will be:
123456Baadvvdwhbdwbdhw test1 test2 test3 test4 test5
test1 here is the test.
test2 here is the test.
test3 here is the test.
123415341636b121313131 test1 test2 test3 test4 test5
here is test5 found.
since I am learning scripting so I have tried this in bits and pieces like:
awk '$1 ~ "B"' file to get first field has B or not
to get fields from 2nd field to last field I used command like:
awk '{for(i=2;i<=NF;i++){print $i}}'
but I am not sure how to do it in a single awk, any guidance is highly appreciated