I have a file some_file.txt , in which I want to find a match line by name inside square brackets (it must bee exact match as some words may be repeated - like foo in example below).
The document contents looks like this:
[foo](url)
[foo Foo](url)
[bar (Bar)](url)
[fizz buzz](url)
I came up with the following, but it breaks when you specify name with paranthesis.
file="some_file.txt"
name="foo" # Good
name="foo Foo" # Good
name="bar (Bar)" # No match :(
name="fizz buzz" # Good
matched_line=$(awk -v n="${name}]" '$0 ~ n {print NR}' "${file}")
I tried to escape paranthesis like so name="bar \(Bar\)", but it doesn't help.