Skip to main content
added 147 characters in body
Source Link
jai_s
  • 1.5k
  • 7
  • 7

sed is clumsy, but here is what I could get -

sed  's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour  product ID is: \2/' 3
Enter product ID: Apple
Your product ID is: 2134

sed  's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 3
Enter product ID: Mango
Your product ID is: 4567

Edited based on latest input which is slightly different

./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: \1\nYour product ID is: \2/' data
sed  's/.*product_id":"\('"$1"'\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' data
sed  's/.*product_id":"\('"$1"'\)","publishName":"\([^"]*\)".*/Enter product ID: \1\nYour publish ID is: \2/' 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> 

 \1 and \2 save the matched expression in \(..\) for later use.

sed is clumsy, but here is what I could get -

sed  's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour  product ID is: \2/' 3
Enter product ID: Apple
Your product ID is: 2134

sed  's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 3
Enter product ID: Mango
Your product ID is: 4567

Edited based on latest input which is slightly different

./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 

#sed  's/.*product_id":"\(Apple\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' data
sed  's/.*product_id":"\('"$1"'\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 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> 

 \1 and \2 save the matched expression in \(..\) for later use.

sed is clumsy, but here is what I could get -

sed  's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour  product ID is: \2/' 3
Enter product ID: Apple
Your product ID is: 2134

sed  's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 3
Enter product ID: Mango
Your product ID is: 4567

Edited based on latest input which is slightly different

./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: \1\nYour product ID is: \2/' data
sed  's/.*product_id":"\('"$1"'\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' data
sed  's/.*product_id":"\('"$1"'\)","publishName":"\([^"]*\)".*/Enter product ID: \1\nYour publish ID is: \2/' 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> 

 \1 and \2 save the matched expression in \(..\) for later use.
added 495 characters in body
Source Link
jai_s
  • 1.5k
  • 7
  • 7

sed is clumsy, but here is what I could get -

sed  's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour  product ID is: \2/' 3
Enter product ID: Apple
Your product ID is: 2134

sed  's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 3
Enter product ID: Mango
Your product ID is: 4567

Edited based on latest input which is slightly different

./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 

#sed  's/.*product_id":"\(Apple\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' data
sed  's/.*product_id":"\('"$1"'\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 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> 

 \1 and \2 save the matched expression in \(..\) for later use.

sed is clumsy, but here is what I could get -

sed  's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour  product ID is: \2/' 3
Enter product ID: Apple
Your product ID is: 2134

sed  's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 3
Enter product ID: Mango
Your product ID is: 4567


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> 

 \1 and \2 save the matched expression in \(..\) for later use.

sed is clumsy, but here is what I could get -

sed  's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour  product ID is: \2/' 3
Enter product ID: Apple
Your product ID is: 2134

sed  's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 3
Enter product ID: Mango
Your product ID is: 4567

Edited based on latest input which is slightly different

./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 

#sed  's/.*product_id":"\(Apple\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' data
sed  's/.*product_id":"\('"$1"'\).*"productBuildId":"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 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> 

 \1 and \2 save the matched expression in \(..\) for later use.
added 243 characters in body
Source Link
jai_s
  • 1.5k
  • 7
  • 7

sed is clumsy, but here is what I could get -

sed  's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour  product ID is: \2/' 3
Enter product ID: Apple
Your product ID is: 2134

sed  's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 3
Enter product ID: Mango
Your product ID is: 4567 


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> 

 \1 and \2 save the matched expression in \(..\) for later use.

explanation : substitute the string Mango : with -> Your product ID is: Mango Your product ID is : \1 and \2 save the matched expression in (..) for later use.

sed is clumsy, but here is what I could get -

sed  's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour  product ID is: \2/' 3
Enter product ID: Apple
Your product ID is: 2134

sed  's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 3
Enter product ID: Mango
Your product ID is: 4567

explanation : substitute the string Mango : with -> Your product ID is: Mango Your product ID is : \1 and \2 save the matched expression in (..) for later use.

sed is clumsy, but here is what I could get -

sed  's/.*\(Apple\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour  product ID is: \2/' 3
Enter product ID: Apple
Your product ID is: 2134

sed  's/.*\(Mango\)[^:]*:"\([0-9]*\)".*/Enter product ID: \1\nYour product ID is: \2/' 3
Enter product ID: Mango
Your product ID is: 4567 


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> 

 \1 and \2 save the matched expression in \(..\) for later use.
added 243 characters in body
Source Link
jai_s
  • 1.5k
  • 7
  • 7
Loading
Source Link
jai_s
  • 1.5k
  • 7
  • 7
Loading