Home > Back-end >  Separate data in <> with cmd
Separate data in <> with cmd

Time:08-11

I have a file with the content as in test.txt file. https://anotepad.com/notes/ktp7yrm4 it includes strings <string><string><string>.....<string> lots more. There is 1 part containing uid: "text="1000***********" contains 16 numbers. I need to separate them by command line in windows 10. please help me.this code t used but it not working:

@echo off 
for /F "delims=" %%I in ('findstr "1000" "test.txt"') do set "LINE=%%I" & for /F "delims=zxcvbnm,.asdfghjkl;: /><?\qwertyuiop[]-=``'' " %%J in ('cmd /V /C "echo/!LINE:*1000^=1000!"') do echo %%J>C:\Users\ADMIN\Pictures\Regfb\uid.txt`

CodePudding user response:

Using sed (I use GNU sed - Google is your friend)

sed s/.*\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\).*/\1/g untitled1.txt >>C:\Users\ADMIN\Pictures\Regfb\uid.txt`

should work for you.

Always verify against a test directory before applying to real data.

CodePudding user response:

This can be done using a regex with powershell and set it into the variable UID with for /f loop like this :


@echo off
Set "PsCommand=Powershell -C "$regex = [regex]'(\d{15})';$data = GC "test.txt";ForEach ($m in $regex.Matches($data)) {$UID= $m.Value}; $UID""
@for /f "delims=" %%a in ('%PsCommand%') do Set "UID=%%a"
echo UID=%UID%
echo %UID%>UID.txt
pause
  • Related