Page 1 of 1
find command not working as expected
Posted: 23 May 2012 14:38
by MKANET
The below command-line produced the following respective output
Command-line:
mt.exe mediastatus tape0Output:
Code: Select all
Capacity (Bytes) : 0x32f2800000 (218816839680)
Remaining (Bytes) : 0x31bfd00000 (213671477248)
Block Size : 0x00000200 (512)
Partition Count : 0x00000000 (0)
Write Protected : No
Current Partition : 0
Absolute Block Position : 0x00000000 0x00000000 (0 0)
Absolute Byte Position : 0x0000000000000000
Status : Ready
If I use the simple command-line shown below to find the string of characters between the quotes, the find command doesnt find anything. Since there's a possibility that there may be other instances of the string "No", I can't search for just "No" unfortunately.
Code: Select all
mt.exe mediastatus tape0| find "Write Protected : No
The find command can find "Write Protected" and ":No" separately, just not together with spaces in between. I have verified that the number of spaces in between are correct.
What's causing find to not work in this case?
Re: find command not working as expected
Posted: 23 May 2012 14:49
by aGerman
Use FINDSTR instead. The /c:"string with spaces" should return what you need.
Regards
aGerman
Re: find command not working as expected
Posted: 23 May 2012 15:01
by MKANET
Hi aGerman, it looks like there is something else wrong. The firststr can't find that string of text either.
Is it because there's a tab in between? However, when I copy and paste that string of text; I only get spaces, I dont get a tab. So, if there's tabs there, they are invisible to me. If it is indeed tabs, how to insert a couple of tab spaces within the quotes?
Also, sorry to make this difficult, but I also have one more thing that's related.
Immediately after the find command, I do an IF statement to check for errorlevel. Is there any way to "find" (or findstr) two completely separate strings from the same output (shown above) and do respective errorlevel checks without writing to a temp file?
Thanks so much aGerman!
Re: find command not working as expected
Posted: 23 May 2012 15:11
by aGerman
Step by step
The console window displays spaces even if tabs are outputted from the tool.
Redirect the output to a file and check with notepad (or even better with a HEX editor) whether tabs are included and what character encoding is returned.
Regards
aGerman
Re: find command not working as expected
Posted: 23 May 2012 15:47
by MKANET
aGerman, that was a great idea! Hexedited the output that was saved to a file. There are two tab spaces exactly
"Write ProtectedTABTAB: No"
Re: find command not working as expected
Posted: 23 May 2012 15:48
by Squashman
MKANET wrote:Immediately after the find command, I do an IF statement to check for errorlevel. Is there any way to "find" (or findstr) two completely separate strings from the same output (shown above) and do respective errorlevel checks without writing to a temp file?
Why write to a temp file? Set a variable equal to something if the find is true. Use the double && for conditional execution.
Re: find command not working as expected
Posted: 23 May 2012 15:53
by MKANET
Could you show me please? I have no idea how to do that. Im not sure how to do && conditional execution.
Lets supposed I first need to check for "Capacity" string from the output. If that's true, then to check whether "write protected :NO" was found or not
(from the same output "Capacity" string came from).
Squashman wrote:MKANET wrote:Immediately after the find command, I do an IF statement to check for errorlevel. Is there any way to "find" (or findstr) two completely separate strings from the same output (shown above) and do respective errorlevel checks without writing to a temp file?
Why write to a temp file? Set a variable equal to something if the find is true. Use the double && for conditional execution.
Re: find command not working as expected
Posted: 23 May 2012 16:07
by aGerman
Is it sufficient to count the found lines?
Untested
Code: Select all
set /a n=0
for /f %%i in ('mt.exe mediastatus tape0^|findstr /c:"string 1" /c:"string 2"') do set /a n+=1
echo %n%
n should be 2 if both strings are found.
Regards
aGerman
Re: find command not working as expected
Posted: 23 May 2012 16:16
by MKANET
Thanks. I'd like to test it out. But, but I still need to somehow specify the tab key twice in "string 2"
aGerman wrote:Is it sufficient to count the found lines?
Untested
Code: Select all
set /a n=0
for /f %%i in ('mt.exe mediastatus tape0^|findstr /c:"string 1" /c:"string 2"') do set /a n+=1
echo %n%
n should be 2 if both strings are found.
Regards
aGerman
Re: find command not working as expected
Posted: 23 May 2012 16:22
by aGerman
If your text editor replaces tabs automatically then you could use notepad to include the tab characters into your code. The tab key causes tab characters in notepad.
Regards
aGerman
Re: find command not working as expected
Posted: 23 May 2012 16:25
by MKANET
It worked brilliantly.. Thanks aGerman!!