Findstr question

June 15, 2009 at 07:47:21
Specs: Windows XP, 2g
This is my text file:
---------------------------------------------------
CentralProfile REG_SZ
CentralProfile REG_SZ
CentralProfile REG_SZ \\ALPLCFP01\PROFILES$\MEBLINE.USR
CentralProfile REG_SZ \\ALXAPFS15\PROFILES$\X2ABERRY.USR
CentralProfile REG_SZ \\ALXAPFS17\PROFILES$\X2BJCUMM.USR
CentralProfile REG_SZ
----------------------------------------------------------

I would like to use findstr to look for \\ and then echo or print the remainder of the line.

This is an example of what what i would like the output to be

\\ALXAPFS15\PROFILES$\X2ABERRY.USR
\\ALXAPFS17\PROFILES$\X2BJCUMM.USR
\\ALPLCFP01\PROFILES$\MEBLINE.USR
--------------------------------------------------

I'v tried diffrent combinations with findstr but can't seem to get the format right.
iv'e tried:
findstr "\<\\ usr\>" c:\profile.txt
findstr "\\ usr\>" c:\profile.txt
and many more combinations with no luck...any suggestions?


See More: Findstr question

Report •


#1
June 15, 2009 at 08:23:54
get gawk for windows here if you can download stuffs..example of how to use
C:\test>gawk "$3{print $3}" file.txt
\\ALPLCFP01\PROFILES$\MEBLINE.USR
\\ALXAPFS15\PROFILES$\X2ABERRY.USR
\\ALXAPFS17\PROFILES$\X2BJCUMM.USR

GNU win32 packages


Report •

#2
June 15, 2009 at 08:31:30
Well this batch file will be run on close to 10,000 PCs on the network so I was hoping to find a solution that would'nt require any installtion programs ex: python, gawk, and other tools.

Thanks for the quick response though!


Report •

#3
June 15, 2009 at 08:59:50

:: MYFND.BAT Usage: myfnd "[drive:][path]filename"
@echo off & setlocal EnableDelayedExpansion
type nul > result.txt
for /F "delims=" %%j in ('type %* ^| find "\\"') do (
  set row=%%j
  set row=!row:*\\=!
  echo.\\!row!>> result.txt
)
echo.
type result.txt
echo.
:: End_Of_Batch

@ghostdog

as ancient Romans said "in Rome speak Latin, in Athen Greek".


Report •

Related Solutions

#4
June 15, 2009 at 09:24:46
IVO, that batch worked beautifully!!
I am trying to add the code into an exsisting batch file though and can't seem to get it right.

the file im using as an input file will always be the same c:\profile.txt

how would i need to code it ?

This is my exsisting batch:
--------------------------------------------------------
cls
echo Connected to %bob%
echo Retrieving Registry info.
echo Please Wait..........


reg query "\\%bob%\hklm\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /s | find "CentralProfile" > C:\profile.txt
Type C:\profile.txt
pause

---------------------This is where I added you code------------

@echo off & setlocal EnableDelayedExpansion
type nul > c:\profile.txt
for /F "delims=" %%j in ('type %* ^| find "\\"') do (
set row=%%j
set row=!row:*\\=!
echo.\\!row!>> c:\profile.txt
)
echo.
type profile.txt

pause
----------------------------------------------------------------------


Report •

#5
June 15, 2009 at 09:50:54
Hi IVO

"set row=!row:*\\=!"

Why the * ?


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#6
June 15, 2009 at 13:11:40
Here your batch ready to run. C:\profile.txt is the input file while C:\result.txt the filtered output (that must have a different name from input). The statement

type nul > C:\result.txt

just clears the output before filtering to avoid duplicate entries in multiple runs. Anyway I'm ready to further support if you need help.

@echo off & setlocal EnableDelayedExpansion
cls
echo.
echo.  Connected to %bob%
echo.  Retrieving Registry info
echo.  Please Wait...
echo.

reg query "\\%bob%\hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\ProfileList" /s | find "CentralProfile" > C:\profile.txt
type C:\profile.txt
pause

type nul > C:\result.txt
for /F "delims=" %%j in ('type C:\profile.txt ^| find "\\"') do (
  set row=%%j
  set row=!row:*\\=!
  echo.\\!row!>> C:\result.txt
)
echo.
type C:\result.txt
pause
:: End_Of_Batch


Report •

#7
June 15, 2009 at 13:28:26
@M2,

set row=!row:*\\=!

means "delete the first occurrence of \\ and all the characters from the beginning of the string to the occurrence".

It works only for the string preceding the occurrence not for the string on the right, i.e.

set row=!row:\\*=!

does not work.


Report •

#8
June 15, 2009 at 13:50:33
The files works great now..you guys have been a wonderful help!!

Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Report •

#9
June 15, 2009 at 14:15:35
Thanks IVO. got it


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#10
June 15, 2009 at 18:21:48
>> Well this batch file will be run on close to 10,000 PCs on the >>network so I was hoping to find a solution that would'nt >>require any installtion programs ex: python, gawk, and other >>tools.

how are you going to distribute your batch anyway? go to those PCs one by one? or do you have software that push down application to those PCs automatically? If you are going to those PCs one by one to install your batch, it makes no difference. I am not asking you to download gawk from those 10000 PCs individually. you can just download gawk once. then bring them to those PCs (either manually or automatically ) together with your batch..

@IVO:
>>> as ancient Romans said "in Rome speak Latin, in Athen Greek".

nowadays, English is the international language. no matter where you are, you are able to communicate with just 1 language. Python, (g)awk, Perl codes , at the very least, can be used on different platforms with no/minimal changes. You will never know when one day you are going to use *nix instead. Therefore, learning to write portable code is no harm.

GNU win32 packages


Report •


Ask Question