ملف دفعي لإخراج السطر الأخير من فيندستر
-
21-12-2019 - |
سؤال
أحاول العثور على قائمة من الأجهزة في الملفات في المجلدات ، وطباعة السطر الأخير من الإخراج فقط.
@echo off
for /f %%a in (computers.txt) do findstr /xs "%%a" unhealthy.txt
pause
أجهزة الكمبيوتر.يحتوي ملف تكست على قائمة من 300 جهاز.
أريد أن أخرج فقط السطر الأخير من كل مثيل يجده.
في الوقت الحالي ، يعرض الأمر ويخرج جميع مثيلات اسم الكمبيوتر ، وليس فقط نهاية الذيل.لقد حاولت استخدام "الذيل ويندوز" ولكن أنا الحصول على أخطاء كذلك.
الانتاج الحالي:
2013\10-Oct\28\unhealthy.txt:WIN57505
2013\10-Oct\29\unhealthy.txt:WIN57505
2013\10-Oct\30\unhealthy.txt:WIN57505
2013\10-Oct\31\unhealthy.txt:WIN57505
2013\11-Nov\1\unhealthy.txt:WIN57505
2013\11-Nov\4\unhealthy.txt:WIN57505
2013\11-Nov\5\unhealthy.txt:WIN57505
2013\11-Nov\6\unhealthy.txt:WIN57505
أريد فقط:
2013\11-Nov\6\unhealthy.txt:WIN57505
المحلول
@echo off
setlocal enableextensions disabledelayedexpansion
for /f %%a in (computers.txt) do (
set "line="
for /f "tokens=*" %%b in ('findstr /xs "%%a" *') do set "line=%%b"
setlocal enabledelayedexpansion
echo(!line!
endlocal
)
pause
endlocal
نصائح أخرى
setLocal enableDelayedExpansion
for /f %%a in (computers.txt) do for /f "tokens=*" %%A in ('findstr /xs "%%a"') do set lastFound=%%A
echo !lastFound!
لا تنتمي إلى StackOverflow