how to write a function to get data under spesific lines ? using bash

I have a text file called ( bvhz ) contains data :

Subscriber
Data ID = 2
Customer = 99
Data ID = 4
Customer = cf99
Data ID = 5
Customer = c99
Data ID = 11
Customer = 9n9

Subscriber
Data ID = 1
Customer = 9ds9
Data ID = 2
Customer = 9sad9
Data ID = 3
Customer = f99
Data ID = 4
Customer = 9sg9
Data ID = 5
Customer = 9sg
Data ID = 8
Customer = 99

And so on for # of subscribers
I want to write a function to get me the customer number under Data ID = 4
Note: number of lines containing data id variable and not in same place 4 every subscriber

Output file >
Cf994
9sg9
Null ------------ if its not found ( data id = 4 under each subscriber )
.....

Please help I think its impossible

Is Customer always immediately after Data ID?

If so you could do:

grep -A1 "Data ID = 4" infile | awk '/Customer/ {print $2}'

(GNU grep)

EDIT: duplicate thread

1 Like