Matt20687 wrote:foxidrive wrote:Matt20687 wrote:The issue i have is there are a couple of examples where a 7 digit number is occurring just before the number i actually want to retrieve. Are we able to add another rule in? The number i need always has sps_id= before and &unreport after, so the question i have is is there anyway we can limit the search from the whole text file?
This should cater for that, with those strings.
sed -n "s/.*sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)&unreport.*/\1/p"
Doesnt seem to work

for /f %%a in ('sed -n "s/.*sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)&unreport.*/\1/p" %ims%') do echo %%a
pause
It is not returning anything at all, it is also not returning any errors when running it. Any ideas foxi?
Thanks,
Matt
Hello,
Ignore this, i realised the information i provided wasnt accurate. I have tweaked it and it now finds the sps number i wanted. The only issue i have is that i need the sps_id that is on the same line as the booking number. An example of what you might see in the ims.txt is:
</script><h2>Book</h2><b>Procedures for NAME</b><br><b>PREFIX-ID</b><p><table class="infotab" cellpadding="4" cellspacing="1"><tr><th>Procedure ID</th><th>Scheduled Date</th><th>Procedure Code</th><th>Procedure Room</th><th>Modality</th><th>Consultant</th><th>Requester</th><th>Referrer</th><th>Report State</th><th>Images</th></tr><tr class="c1" onClick="ii0('op=editexam&patient_id=PREFIX-ID&sps_id=1234567');"><td>
ABC1234567</td><td>Oct 31 2011 3:09PM</td><td>US Abdomen</td><td></td><td>US</td><td></td><td> </td><td></td><td>Do not report</td><td>11</td></tr><tr class="c2" onClick="ii0('op=editexam&patient_id=PREFIX-ID&sps_id=2345678');"><td>ABC2346547</td><td>Jan 6 2012 12:43PM</td><td>MR Derriford</td><td></td><td>MR</td><td></td><td> </td><td></td><td>Do not report</td><td>104</td></tr><tr class="c1" onClick="ii0('op=editexam&patient_id=PREFIX-ID&sps_id=3456789');"><td>BCA1234567
The code i am using is:
set acc=acc.txt
set ims=ims.txt
set "sps=');"
for /f %%a in ('sed -n "s/.*sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)%sps%.*/\1/p" %ims%') do echo %%a
pause
I need to be able to have the above code work as it is but also look at the numbers i have stored within acc.txt. In there you would have an ID as
ABC1234567
I have highlighted above where this occurs in ims.txt. So in this instance i would like the code to do what it does looking between sps_id= and %sps% and then returning the 7 digit number but it needs to be able to check it is returning the sps_id number which has ABC1234567 in the same line.
With the code as it is there is no definition as to which one it will take, there is a possiblilty that i could return:
2345678
This has the ID ABC2346547 on the same line.
Does this make sense foxi or anyone?
Thanks,
Matt