Searching html? Can a batch file do this?
Moderator: DosItHelp
Re: Searching html? Can a batch file do this?
Will each entry always appear in this format?
Will the bit in blue always appear between the number that you want and the reference that you have - ABC1234567 in this case?
patient_id=PREFIX-ID&sps_id=1234567');"><td>ABC1234567</td>
And what is the task?
Do you have acc.txt that contains a list of these reference numbers and you want to extract the 7 digit numbers for all of them from the html?
Will the bit in blue always appear between the number that you want and the reference that you have - ABC1234567 in this case?
patient_id=PREFIX-ID&sps_id=1234567');"><td>ABC1234567</td>
And what is the task?
Do you have acc.txt that contains a list of these reference numbers and you want to extract the 7 digit numbers for all of them from the html?
Re: Searching html? Can a batch file do this?
Matt20687 wrote:I have been testing a few things and i have found that the sed commands is not actually refering to my variable at all! I deleted the variable set "sps=');" which is defined at the start of my script and it still returned the same values
Yes, I wondered why you put that there. You assumed it was going to do something but as the addition you made wasn't going to change the result I didn't comment on it because the task was changing anyway.
Re: Searching html? Can a batch file do this?
foxidrive wrote:Will each entry always appear in this format?
Will the bit in blue always appear between the number that you want and the reference that you have - ABC1234567 in this case?
patient_id=PREFIX-ID&sps_id=1234567');"><td>ABC1234567</td>
And what is the task?
Do you have acc.txt that contains a list of these reference numbers and you want to extract the 7 digit numbers for all of them from the html?
Hello foxi,
Yes you are right the bit in blue always appears between the sps ID and the reference in this which is ABC1234567. I have a text file named acc (acc.txt) which holds all of the reference numbers such as ABC1234567 and I would like to extract the 7 digit number (which is after sps_id=) which is on the same line as the reference number (held in acc.txt)
Re: Searching html? Can a batch file do this?
This works here with the sample html that you posted.
Code: Select all
@echo off
for /f "delims=" %%a in ('type "acc.txt"') do (
for /f "delims=" %%b in ('sed -n "s/.*sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1/p" "lms.txt"') do (
echo the reference "%%a" returns number "%%b"
rem run your commands here for the 7 digit number contained in %%b
)
)
Re: Searching html? Can a batch file do this?
foxidrive wrote:This works here with the sample html that you posted.Code: Select all
@echo off
for /f "delims=" %%a in ('type "acc.txt"') do (
for /f "delims=" %%b in ('sed -n "s/.*sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1/p" "lms.txt"') do (
echo the reference "%%a" returns number "%%b"
rem run your commands here for the 7 digit number contained in %%b
)
)
You are a legend foxi!!! Works a treat thanks. I do appreciate all of your help, I only hope I can relay what I have learnt onto someone else who in need of assistance.
Thanks Again.
Matt
Re: Searching html? Can a batch file do this?
Matt20687 wrote:foxidrive wrote:This works here with the sample html that you posted.Code: Select all
@echo off
for /f "delims=" %%a in ('type "acc.txt"') do (
for /f "delims=" %%b in ('sed -n "s/.*sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1/p" "lms.txt"') do (
echo the reference "%%a" returns number "%%b"
rem run your commands here for the 7 digit number contained in %%b
)
)
You are a legend foxi!!! Works a treat thanks. I do appreciate all of your help, I only hope I can relay what I have learnt onto someone else who in need of assistance.
Thanks Again.
Matt
Hello foxi,
I thought i had finished!! Got right near the end and discovered i need a similar thing as to what you have provided me. Instead i need to search the same ims.txt file but instead of returning the sps number i need to return a ID, the number is inbetween a - and &sps_id so the layout would be:
-ID&sps_id
The difference in this one is that i need it to return the ID as i have shown above, the ID is not a specific length and can have both numeric and alphabetical characters (such as ABC123 or C12345677).
Are you able to tweak your code to be able to return the middle text/number as specified above?
Re: Searching html? Can a batch file do this?
I think this is what you want:
Code: Select all
@echo off
for /f "delims=" %%a in ('type "acc.txt"') do (
for /f "tokens=1,2" %%b in ('sed -n "s/.*-\(.*\)&sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1 \2/p" "lms.txt"') do (
echo the reference "%%a" returns ID="%%b" and number "%%c"
rem run your commands here for the 7 digit number contained in %%b
)
)
pause
Re: Searching html? Can a batch file do this?
foxidrive wrote:I think this is what you want:Code: Select all
@echo off
for /f "delims=" %%a in ('type "acc.txt"') do (
for /f "tokens=1,2" %%b in ('sed -n "s/.*-\(.*\)&sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1 \2/p" "lms.txt"') do (
echo the reference "%%a" returns ID="%%b" and number "%%c"
rem run your commands here for the 7 digit number contained in %%b
)
)
pause
Going to try it now, thanks.
Out of interest where does it pull %%c from?
Re: Searching html? Can a batch file do this?
The "tokens=1,2" will allocate two variables to items of text that are separated by a space. The sed command returns the two items in \1 and \2