Page 1 of 1

Find text string in TXT hosted on Server.

Posted: 30 Jan 2022 07:19
by MauricioDeAbreu
Friends, I need to search for a text string (Laptop Serial. Example 1SWA12F45G68B2) in a TXT file (Serials.txt), but this TXT file is hosted on an IP address of a server.

This Batch would run under the following Operating Systems: Windows XP, Seven and 10

Is there a way to do it from a Batch?

Thanks in advance for any help you can give me.

Excuse my English, I use a translator.

Re: Find text string in TXT hosted on Server.

Posted: 30 Jan 2022 10:22
by Squashman
So you know the name of the server. You know the severs ip address. You know the name of the file you need to search. You know what the search string is. What is your problem?

Re: Find text string in TXT hosted on Server.

Posted: 30 Jan 2022 11:06
by MauricioDeAbreu
The problem is that I don't know how to do it :-(

This is how I do it in the same directory.

@Echo Off
::test value
set serial=1S2887PS099XGA21

Find "%serial%" Seriales.txt >NUL
If %ERRORLEVEL% EQU 1 (
Echo serial does not exist : %serial%
) Else (
Echo Serial existe: %serial%
)
pause

Re: Find text string in TXT hosted on Server.

Posted: 30 Jan 2022 11:42
by Squashman
So if you have files on another computer on your network how do you get to them?

(Teaching you to fish)

Re: Find text string in TXT hosted on Server.

Posted: 30 Jan 2022 13:18
by MauricioDeAbreu
I was looking for information about it, and on this page https://docs.microsoft.com/es-es/dotnet ... th-formats I found the following:

Code: Select all

@"\\127.0.0.1\c$\temp\test-file.txt"
I guess it would be something like this:

Code: Select all

@Echo Off
::test value
set serial=1S2887PS099XGA21

Find "%serial%" @"\\127.0.0.1\c$\Seriales.txt” >NUL
If %ERRORLEVEL% EQU 1 (
Echo serial does not exist : %serial%
) Else (
Echo Serial existe: %serial%
)
pause
I don't know if the double \\, the @ or the c$ is used

Thanks for your time

Re: Find text string in TXT hosted on Server.

Posted: 30 Jan 2022 13:31
by ShadowThief
You can't interact with remote files.

Download the file and interact with the local copy.

Re: Find text string in TXT hosted on Server.

Posted: 31 Jan 2022 09:22
by MauricioDeAbreu
Thanks for answering.

And how do you copy a file located on a server? :oops:

Thanks in advance for the help.

Re: Find text string in TXT hosted on Server.

Posted: 31 Jan 2022 09:55
by ShadowThief
curl, generally, since that's built into Windows 10 and 11.

Re: Find text string in TXT hosted on Server.

Posted: 31 Jan 2022 12:48
by MauricioDeAbreu
And Curl can be used on Windows Xp and Seven ?

Re: Find text string in TXT hosted on Server.

Posted: 31 Jan 2022 14:40
by ShadowThief
You'd have to install it separately, but Windows XP and 7 are wildly out of date and shouldn't be used.

Re: Find text string in TXT hosted on Server.

Posted: 01 Feb 2022 10:22
by atfon
For older operating systems, you could potentially use BitsTransfer with powershell as in this StackOverflow Answer:

https://stackoverflow.com/questions/302 ... lternative

Re: Find text string in TXT hosted on Server.

Posted: 01 Feb 2022 16:59
by MauricioDeAbreu
Thank you for your answers.

Due to the activities we do, it is impossible to leave Windows XP (64bit) and Windows Seven.

At work we use three operating systems, Windows XP (64bit), Windows Seven and Windows 10.

So any code you make must be compatible with all three operating systems.

Regarding my question, and from what you guys say, it's impossible to do the following with Batch alone:
1- Look for the serial of the laptop in a txt file that is in another computer (server).
2- Copy a TXT file from one computer (server) to another computer (Laptop).

If these statements are correct, I have to find an alternative to look up the equipment serial in a list. It is essential that the serial is validated in the file or list.

So I'm wondering:
Will it be possible to search for the serial (text string) in a list that is on a web page on another computer (server)?
That is, query the serial at 192.168.100.2/serials.html or something like that.

Any ideas.

I am going to read about BITSAdmin.exe