I have created a simple convertor.

It asks for input (EG. A decimal, binary, hex, or other type of string), then pulls up the matching line, which displays the string in the format entered, along with its equivalent values for the other formats.

An example output for decimal 25 looks like this:

Decimal: 25 Binary: 00011001 (other formats shown)
Decimal: 250 Binary: 11111010 (other formats shown)
Decimal: 251 Binary: 11111100 (other formats shown)

How can I make it so that it only shows the exact match for the decimal search (EG. Only 25, not 250, 251, etc.)?

2 Answers 2


Using regex word boundaries \b:

$ grep '\b25\b' file
Decimal: 25 Binary: 00011001 (other formats shown)

or using awk:

$ awk '$2 == 25' file
  • I'm no expert with regex, and TBH, it seems like something I need to look into (unless I've been using it without knowing it :D ). I'll make a note of the boundary solution you've provided, it may come in handy in future functions. Thank you for the help :)
    – Lee
    Oct 23, 2022 at 2:51
  • Advice to newcomers: If an answer solves your problem, please accept it by clicking the large check mark (✓) next to it and optionally also up-vote it (up-voting requires at least 15 reputation points). If you found other answers helpful, please up-vote them. Accepting and up-voting helps future readers. Please see the relevant help-center article Oct 23, 2022 at 2:57

Include the space after the match in the grep query. For example:

grep -i "string "

rather than

grep -i "string"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .