Skip to main content
added 444 characters in body
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118

I used grep command with \k notify and lookbehind assertion:

$ read name Jan # input Jan $name; echo "The phone number of $name is $(grep -oP "$name;\K.*" telephone)"  Jan  #Input The phone number of Jan is 032569874 #output#Output 

grep with -P(perl-regexp) parameter supports \K, which use to ignoring the previously matched characters(ignore name and semicolon;).

-o, --only-matching: print only the matched (non-empty) parts of a matching line.

$(command) "Command Substitution" that allows the output of a command to replace the command name.

Or you can use the lookbehind assertion in place of nifty \K.

$ read name; echo "The phone number of $name is $(grep -oP "(?<=$name;).*" telephone)" 
$ read name Jan # input Jan $ echo "The phone number of $name is $(grep -oP "$name;\K.*" telephone)" The phone number of Jan is 032569874 #output 

I used grep command with \k notify and lookbehind assertion:

$ read name; echo "The phone number of $name is $(grep -oP "$name;\K.*" telephone)"  Jan  #Input The phone number of Jan is 032569874 #Output 

grep with -P(perl-regexp) parameter supports \K, which use to ignoring the previously matched characters(ignore name and semicolon;).

-o, --only-matching: print only the matched (non-empty) parts of a matching line.

$(command) "Command Substitution" that allows the output of a command to replace the command name.

Or you can use the lookbehind assertion in place of nifty \K.

$ read name; echo "The phone number of $name is $(grep -oP "(?<=$name;).*" telephone)" 
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118

$ read name Jan # input Jan $ echo "The phone number of $name is $(grep -oP "$name;\K.*" telephone)" The phone number of Jan is 032569874 #output