Remove Wild Card from text file and process each line of text file

Hi I have a text file with SID having wild cards (*) with first character of each line is empty space eg: sid.txt

I hereby need to process each line (convert to username) and assign it to variable, I have tried to remove * using traditional find and replace command but couldn't.

Need assistance
sid.txt
nssasikumarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerCommented:
Hope this is readable to you (Powershell):

foreach ($lineread in get-content sid.txt) {
    foreach($sidline in $lineread.Split(",")) {
        foreach ($sid in $sidline.Split("*")) {
            if  (-not $sid.StartsWith(" ") -and (-not $sid -eq "")) {
                $varyouwant = $sid
                write-host $varyouwant
            }

        }
    }
}

Open in new window


Obviously, pay attention to $varyouwant and use it as you like.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oBdACommented:
Plain batch:
@echo off
setlocal enabledelayedexpansion
set InFile=C:\Temp\sid.txt
REM *** Add SID file pre-processing code here

REM *** The following line processes the file with the sids:
for /f "delims=" %%a in ('type "%InFile%"') do (call :ProcessSid %%a)
REM *** Add SID file post-processing code here

REM End of main script; functions only below this point!
goto :eof
:ProcessSid
set Sid=%1
set Sid=%Sid:~1%
echo Processing SID: %Sid%
REM *** Add SID specific code here

if "%~2"=="" goto :eof
shift
goto ProcessSid

Open in new window

0
oBdACommented:
And here's a version that tries to resolve the SID to a name, using Sysinternal's PsGetSid (https://technet.microsoft.com/en-us/sysinternals/bb897417.aspx) (with slight changes to the initial script above to make return from the sub easier):
@echo off
setlocal enabledelayedexpansion
set InFile=C:\Temp\sid.txt
REM *** Add SID file pre-processing code here

REM *** This line processes the file with the sids
for /f "delims=" %%a in ('type "%InFile%"') do (call :ProcessSid %%a)
REM *** Add SID file post-processing code here

REM *** End of main script; functions only below this point!
goto :eof
:ProcessSid
if "%~1"=="" goto :eof
set Sid=%1
shift
set Sid=%Sid:~1%
echo Processing SID: %Sid% ...
REM *** Add SID specific code here
set Account=
for /f "skip=1 tokens=1* delims=:" %%a in ('psgetsid.exe -accepteula %SID% 2^>NUL') do set Account=%%~b
if "%Account%"=="" (
	echo Error: no account found for SID %SID%
	goto ProcessSid
)
set Account=%Account:~1%
echo ... Account: %Account%


goto ProcessSid
REM *** End of script

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.