Extracting a string from html tag

Hi

I am new to string extractions in shell script... I am trying to extract a string such as #1753 from html tag looks like below.

<a class="model-link tl-tr" href="lastSuccessfulBuild/">Last successful build (#1753), 40 min ago</a>

and want the value as

1753

Could someone help me to do this? Thank you very much for your kind attention in advance.

/h

Using parameter substitution on any POSIX shell:

str='<a class="model-link tl-tr" href="lastSuccessfulBuild/">Last successful build (#1753), 40 min ago</a>'
str="${str##*(#}"
echo "${str%%)*}"

Using awk program:

echo "<a class="model-link tl-tr" href="lastSuccessfulBuild/">Last successful build (#1753), 40 min ago</a>" | awk '{gsub(/.*\(#|\).*/,x)}1'

Using sed

sed 's/.*(#\([0-9]*\)).*/\1/g' input_file

--ahamed

I guess the input file do contain more than this single line. Here is how I would do it.

awk -F"#|)" '/lastSuccessfulBuild/ {print $2}' infile
1753