sed é desajeitado, mas aqui está o que eu consegui -
sed 's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \nYour product ID is: /' 3
Enter product ID: Apple
Your product ID is: 2134
sed 's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \nYour product ID is: /' 3
Enter product ID: Mango
Your product ID is: 4567
Editado com base na entrada mais recente, ligeiramente diferente
./prod.sed Apple
Enter product ID: Apple
Your product ID is: 1234
./prod.sed Mango
Enter product ID: Mango
Your product ID is: 12345
prod.sed (use 3rd line for publishName)
#sed 's/.*product_id":"\(Apple\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \nYour product ID is: /' data
sed 's/.*product_id":"\('"$1"'\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \nYour product ID is: /' data
sed 's/.*product_id":"\('"$1"'\)","publishName":"\([^"]*\)".*/Enter product ID: \nYour publish ID is: /' data
explanation : substitute the string <anything> Mango <anything other than :> : <number> with -> Your product ID is: Mango <next line>
Your product ID is : <the number we got>
and save the matched expression in \(..\) for later use.