Issue
I have an html file with numbers. I need to select only numbers. How to get only number 258108 and 263431?
view
258108
263431
<p class="list-item">
<span style="margin-left: 20px" class="padding"></span>
<span class="icon left drop-down-icon" onclick="toggle(this, '15CF78F7-594A-4A8A-9DDC-E4896E9DB430')"></span>
testIT: C258108, testIT: C263431 (1m19s)
<span class="icon paperclip-icon" style="display: inline-block"></span>
</p>
I did
sed -n -e 's/^.*testIT: C//p' | sed -r 's/ .+//'
but I only get the last one 263431
Solution
Since you are not substituting pattern occurrences, perhaps grep would be a better choice for you.
Assuming that you are looking to capture numbers following C
before testIT:
You could try this grep/cut combination:
cat input.txt | grep -o -E 'testIT: C[0-9]+'|cut -d " " -f2|cut -c 2-
grep arguments used:
- -o shows only the matching portions of the input
- -E enables extended regex use
The first cut command simply extracts the second value after testIT:
and the second removes the prepended C
character
Answered By - kiyell Answer Checked By - David Goodson (WPSolving Volunteer)