AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1514312
Accepted
Elisha Habinsky
Elisha Habinsky
Asked: 2020-01-03 17:58:54 +0800 CST2020-01-03 17:58:54 +0800 CST 2020-01-03 17:58:54 +0800 CST

在 CMD 中添加空格以选择字符串时加入行并不总是有效

  • 772

这是一个普通的 .bat ,它连接所有行并在结果字符串之间留下一个空格。

@echo off
setlocal EnableDelayedExpansion
set row=
@For /F "EOL=|" %%x In ('^""%__AppDir__%find.exe" "."^<"%userprofile%\i.txt"^"') Do @Set "row=!row! %%x"
echo %row% >%userprofile%\o.txt
echo %row%

这是该脚本的测试输入:

PDF

wikkipedia.ord
notavalidURL
snapfish.com
.tunnelbear.com
mail.google.com/mail/u/0/#inbox

它输出,完全可以预见:

wikkipedia.ord snapfish.com .tunnelbear.com mail.google.com/mail/u/0/#inbox!

但这是另一个行为方式不同的输入:

PDF
Tech
TORONTO
>
SOME PERSON
Some Company
BusinessName

User Name
Users
Default User
Default Filter Profile
Web Exceptions
BackWeb Exceptions
Applied URL Lists
Attach List
Individual Exceptions
Applied individually to User and can be modified

Individual List32 URLs
BBC Weather

Shared ListTechloq7 URLs
Bing Search
Allows "bing" search

Shared ListTechloq45 URLs
Business Essential Sites
pre-approved business sites, (from reference, Technology, File sharing, shopping etc).

Shared ListTechloq167 URLs
Email [Gmail]
Allow Gmail Yahoo and AOL mail.

Shared ListTechloq77 URLs
Google Drive

Shared ListTechloq35 URLs
Google hangouts

Shared ListTechloq8 URLs
Google Maps

Shared ListTechloq33 URLs
Google Photos

Shared ListTechloq5 URLs
Jewish Music

Shared ListTechloq89 URLs
Jewish Websites
Allows all jewish websites.

Shared ListTechloq1183 URLs
Microsoft [and google] Office blacklist
Blocks in app browsing for Microsoft apps [office 365, start menu etc.] and for google docs.

Shared ListTechloq18 URLs
Microsoft Classroom

Shared ListTechloq25 URLs
Microsoft maps app
Allows the Microsoft map app

Shared ListTechloq1 URLs
Microsoft Online

Shared ListTechloq27 URLs
Microsoft Teams

Shared ListTechloq28 URLs
Mostlymusic.com

Shared ListTechloq17 URLs
Office Activate
Activate Microsoft office

Shared ListTechloq7 URLs
Religious Blacklist
Blocks ëôéøä websites.

Shared ListTechloq23 URLs
Techloq Global List
For back end and content servers [recaptcha etc.]

Shared ListTechloq261 URLs
Torah Websites

Shared ListTechloq115 URLs
Windows Store blacklist

Shared ListTechloq12 URLs
Windows Update
You might need to add .microsoft.com to the ssl list.

Shared ListTechloq16 URLs
Yahoo Search
Allows Yahoo search

Shared ListTechloq42 URLs
Individual Exceptions
Applied individually to User and can be modified

Individual ListLast changed Dec 26, 2019 09:35 AM
URLs Included
Access  
Offensive Text Filter
Images Filter
Video Blocking
Type URL and press Enter
On
On
On
wikkipedia.ord
Time left 13d 34m
Go to Temporary Access
youtubedownload.video
On
On
Off
.slack.com
Off
Off
Off
slack.com
Off
Off
Off
snapfish.com
On
Off
On
.tunnelbear.com
On
On
Off
mail.google.com/mail/u/0/#inbox
On
Off
Off
google.com/url?q=https://connect.cloudberrylab.com?i%3D448781782&source=gmail&ust=1573146628917000&usg=AFQjCNF14Y-dux0_bNSOc-jOfjLgHy-3fw
On
On
On
connect.cloudberrylab.com?i=448781782
On
Off
Off
golantelecom.co.il
On
On
Off
msn.com
citibank.com
On
On
Off
youtube.com/watch?v=TsBcex3M2Xo&list=RDTsBcex3M2Xo&start_radio=1&t=0
On
Off
Off
youtube.com/watch?v=TsBcex3M2Xo&list=PL8CN8XjdSyu0TdNKo9U9sF1RL7NB3_0mh
On
Off
Off
ontimestudios.com
On
Off
Off
ontimerovideo.com
On
Off
Off
badchen.com
On
Off
Off
ebay.com/
On
On
On
offshorecompany.com
On
On
On
offshorecompany.com/company/israel-llc/
On
On
On
wikipedia.org
On
On
On
ravkavonline.co.il
On
On
On
tunnelbear.com
On
On
On
citiprivatepass.com
On
On
On
docs.google.com
On
On
On
play.google.com
On
On
On
myjewishcolorado.org
On
On
On
hillelacademyofdenver.com/
On
On
On
wikkipedia.com
On
On
On
productforums.google.com
On
On
On
ultrasurf.us
On
On
On
stackoverflow.com
On
On
On
tutorialpoint.com
On
On
On
Dec 29, 2019 12:23 AM

它会输出一些相当烦人的东西:

 pre-approved business sites, (from reference, Technology, File sharing, shopping etc). Allow Gmail Yahoo and AOL mail. Allows all jewish websites. Blocks in app browsing for Microsoft apps [office 365, start menu etc.] and for google docs. Mostlymusic.com Blocks δ⌠Θ°Σ websites. For back end and content servers [recaptcha etc.] You might need to add .microsoft.com to the ssl list. wikkipedia.ord youtubedownload.video .slack.com slack.com snapfish.com .tunnelbear.com mail.google.com/mail/u/0/#inbox google.com/url?q=https://connect.cloudberrylab.com?i%3D448781782
'source' is not recognized as an internal or external command,
operable program or batch file.
'ust' is not recognized as an internal or external command,
operable program or batch file.
'usg' is not recognized as an internal or external command,
operable program or batch file.
'list' is not recognized as an internal or external command,
operable program or batch file.
'start_radio' is not recognized as an internal or external command,
operable program or batch file.
'1' is not recognized as an internal or external command,
operable program or batch file.
'list' is not recognized as an internal or external command,
operable program or batch file.

为什么这个字符串不同,我如何更改我的 .bat 以获得与第一次尝试相同类型的输出?

以下是似乎与错误相关的刺痛:

'source' is not recognized as an internal or external command
operable program or batch file.
google.com/url?q=https://connect.cloudberrylab.com?i%3D448781782&source=gmail&ust=1573146628917000&usg=AFQjCNF14Y-dux0_bNSOc-jOfjLgHy-3fw

'ust' is not recognized as an internal or external command
operable program or batch file.
google.com/url?q=https://connect.cloudberrylab.com?i%3D448781782&source=gmail&ust=1573146628917000&usg=AFQjCNF14Y-dux0_bNSOc-jOfjLgHy-3fw
'usg' is not recognized as an internal or external command
operable program or batch file.
google.com/url?q=https://connect.cloudberrylab.com?i%3D448781782&source=gmail&ust=1573146628917000&usg=AFQjCNF14Y-dux0_bNSOc-jOfjLgHy-3fw
'list' is not recognized as an internal or external command,
operable program or batch file.
youtube.com/watch?v=TsBcex3M2Xo&list=RDTsBcex3M2Xo&start_radio=1&t=0
'start_radio' is not recognized as an internal or external command,
operable program or batch file.

youtube.com/watch?v=TsBcex3M2Xo&list=RDTsBcex3M2Xo&start_radio=1&t=0
'1' is not recognized as an internal or external command,
operable program or batch file.

youtube.com/watch?v=TsBcex3M2Xo&list=RDTsBcex3M2Xo&start_radio=1&t=0
'list' is not recognized as an internal or external command,
operable program or batch file.
youtube.com/watch?v=TsBcex3M2Xo&list=PL8CN8XjdSyu0TdNKo9U9sF1RL7NB3_0mh

查看输出我可以看到所有引发错误的单词都位于一个字符旁边&(如果这对任何人都意味着什么)。

更令人沮丧的是,我专门编写了这段代码,以便处理来自某个网​​站的文本。每次我将该站点的页面复制到记事本并运行我的代码时,都会发生同样的事情,所以在我解决这个问题之前我什么都没有 在此处输入图像描述

我试图避免使用 CMD 以外的任何代码(即 powershell、cygwin、paste.exe)

cmd.exe find-and-replace
  • 1 1 个回答
  • 150 Views

1 个回答

  • Voted
  1. Best Answer
    Io-oI
    2020-01-21T08:49:56+08:002020-01-21T08:49:56+08:00

    • 您忘记了 bat/cmd 作业在字符串操作中的重要内容...

      您需要对特殊字符使用转义..., &, ?, >, etc,...。

    • 您的文件多次出现


    您可以使用set /p "'="在文件中获取此输出而无需转义特殊字符,因为此命令使用引号:set /p"'=!row!"


    echo %row% >%userprofile%\o.txt 
    || 而是:|| 
    设置 /p "'=!row!" >"%userprofile%\o.txt"

    • 选项 #1 - == 搜索。(字面点)find.exe "."


    • 选项#2 - == 搜索任何(正则表达式任何字符)findstr.exe .



    • 如果您需要选项#1:

    @echo off && setlocal enabledelayedexpansion
    
    cls & title ..\%~nx0 && pushd %userprofile%
    set "_row="<nul && for /f eol^=^| %%x in ('
    ^""%__appdir__%findstr.exe" . ^<".\i.txt"^"
    ')do set "_row=!_row! %%x"
    
    >"%userprofile%\o.txt" set/p "'=!_row!"<nul
    echo[!_row! && podp && endlocal && ;exit /b 
    

    • 选项 #1 结果:
    pre-approved Allow Allows Blocks Mostlymusic.com Blocks For You wikkipedia.ord youtubedownload.video .slack.com slack.com snapfish.com .tunnelbear.com mail.google.com/mail/u/0/#inbox google.com/url?q=https://connect.cloudberrylab.com?i%3D448781782&source=gmail&ust=1573146628917000&usg=AFQjCNF14Y-dux0_bNSOc-jOfjLgHy-3fw connect.cloudberrylab.com?i=448781782 golantelecom.co.il msn.com citibank.com youtube.com/watch?v=TsBcex3M2Xo&list=RDTsBcex3M2Xo&start_radio=1&t=0 youtube.com/watch?v=TsBcex3M2Xo&list=PL8CN8XjdSyu0TdNKo9U9sF1RL7NB3_0mh ontimestudios.com ontimerovideo.com badchen.com ebay.com/ offshorecompany.com offshorecompany.com/company/israel-llc/ wikipedia.org ravkavonline.co.il tunnelbear.com citiprivatepass.com docs.google.com play.google.com myjewishcolorado.org hillelacademyofdenver.com/ wikkipedia.com productforums.google.com ultrasurf.us stackoverflow.com tutorialpoint.com
    


    • 如果您需要选项 #2:
    @echo off && setlocal enabledelayedexpansion
    
    cls & title ..\%~nx0 && pushd %userprofile%
    set "_row="<nul && for /f eol^=^| %%x in ('
    ^""%__appdir__%findstr.exe" . ^<".\i.txt"^"
    ')do set "_row=!_row! %%x"
    
    >"%userprofile%\o.txt" set/p "'=!_row!"<nul
    echo[!_row! && podp && endlocal && ;exit /b
    

    • 选项 #2 结果:
    PDF TechLog TAG > SOME Some BusinessName User Users Default Default Web BackWeb Applied Attach Individual Applied Individual BBC Shared Bing Allows Shared Business pre-approved Shared Email Allow Shared Google Shared Google Shared Google Shared Google Shared Jewish Shared Jewish Allows Shared Microsoft Blocks Shared Microsoft Shared Microsoft Allows Shared Microsoft Shared Microsoft Shared Mostlymusic.com Shared Office Activate Shared Religious Blocks Shared Techloq For Shared Torah Shared Windows Shared Windows You Shared Yahoo Allows Shared Individual Applied Individual URLs Access Offensive Images Video Type On On On wikkipedia.ord Time Go youtubedownload.video On On Off .slack.com Off Off Off slack.com Off Off Off snapfish.com On Off On .tunnelbear.com On On Off mail.google.com/mail/u/0/#inbox On Off Off google.com/url?q=https://connect.cloudberrylab.com?i%3D448781782&source=gmail&ust=1573146628917000&usg=AFQjCNF14Y-dux0_bNSOc-jOfjLgHy-3fw On On On connect.cloudberrylab.com?i=448781782 On Off Off golantelecom.co.il On On Off msn.com citibank.com On On Off youtube.com/watch?v=TsBcex3M2Xo&list=RDTsBcex3M2Xo&start_radio=1&t=0 On Off Off youtube.com/watch?v=TsBcex3M2Xo&list=PL8CN8XjdSyu0TdNKo9U9sF1RL7NB3_0mh On Off Off ontimestudios.com On Off Off ontimerovideo.com On Off Off badchen.com On Off Off ebay.com/ On On On offshorecompany.com On On On offshorecompany.com/company/israel-llc/ On On On wikipedia.org On On On ravkavonline.co.il On On On tunnelbear.com On On On citiprivatepass.com On On On docs.google.com On On On play.google.com On On On myjewishcolorado.org On On On hillelacademyofdenver.com/ On On On wikkipedia.com On On On productforums.google.com On On On ultrasurf.us On On On stackoverflow.com On On On tutorialpoint.com On On On Dec
    


    • 文件“.\i.txt”内容:
    PDF
    TechLog
    TAG TORONTO
    >
    SOME PERSON
    Some Company
    BusinessName
    
    User Name
    Users
    Default User
    Default Filter Profile
    Web Exceptions
    BackWeb Exceptions
    Applied URL Lists
    Attach List
    Individual Exceptions
    Applied individually to User and can be modified
    
    Individual List32 URLs
    BBC Weather
    
    Shared ListTechloq7 URLs
    Bing Search
    Allows "bing" search
    
    Shared ListTechloq45 URLs
    Business Essential Sites
    pre-approved business sites, (from reference, Technology, File sharing, shopping etc).
    
    Shared ListTechloq167 URLs
    Email [Gmail]
    Allow Gmail Yahoo and AOL mail.
    
    Shared ListTechloq77 URLs
    Google Drive
    
    Shared ListTechloq35 URLs
    Google hangouts
    
    Shared ListTechloq8 URLs
    Google Maps
    
    Shared ListTechloq33 URLs
    Google Photos
    
    Shared ListTechloq5 URLs
    Jewish Music
    
    Shared ListTechloq89 URLs
    Jewish Websites
    Allows all jewish websites.
    
    Shared ListTechloq1183 URLs
    Microsoft [and google] Office blacklist
    Blocks in app browsing for Microsoft apps [office 365, start menu etc.] and for google docs.
    
    Shared ListTechloq18 URLs
    Microsoft Classroom
    
    Shared ListTechloq25 URLs
    Microsoft maps app
    Allows the Microsoft map app
    
    Shared ListTechloq1 URLs
    Microsoft Online
    
    Shared ListTechloq27 URLs
    Microsoft Teams
    
    Shared ListTechloq28 URLs
    Mostlymusic.com
    
    Shared ListTechloq17 URLs
    Office Activate
    Activate Microsoft office
    
    Shared ListTechloq7 URLs
    Religious Blacklist
    Blocks ëôéøä websites.
    
    Shared ListTechloq23 URLs
    Techloq Global List
    For back end and content servers [recaptcha etc.]
    
    Shared ListTechloq261 URLs
    Torah Websites
    
    Shared ListTechloq115 URLs
    Windows Store blacklist
    
    Shared ListTechloq12 URLs
    Windows Update
    You might need to add .microsoft.com to the ssl list.
    
    Shared ListTechloq16 URLs
    Yahoo Search
    Allows Yahoo search
    
    Shared ListTechloq42 URLs
    Individual Exceptions
    Applied individually to User and can be modified
    
    Individual ListLast changed Dec 26, 2019 09:35 AM
    URLs Included
    Access  
    Offensive Text Filter
    Images Filter
    Video Blocking
    Type URL and press Enter
    On
    On
    On
    wikkipedia.ord
    Time left 13d 34m
    Go to Temporary Access
    youtubedownload.video
    On
    On
    Off
    .slack.com
    Off
    Off
    Off
    slack.com
    Off
    Off
    Off
    snapfish.com
    On
    Off
    On
    .tunnelbear.com
    On
    On
    Off
    mail.google.com/mail/u/0/#inbox
    On
    Off
    Off
    google.com/url?q=https://connect.cloudberrylab.com?i%3D448781782&source=gmail&ust=1573146628917000&usg=AFQjCNF14Y-dux0_bNSOc-jOfjLgHy-3fw
    On
    On
    On
    connect.cloudberrylab.com?i=448781782
    On
    Off
    Off
    golantelecom.co.il
    On
    On
    Off
    msn.com
    citibank.com
    On
    On
    Off
    youtube.com/watch?v=TsBcex3M2Xo&list=RDTsBcex3M2Xo&start_radio=1&t=0
    On
    Off
    Off
    youtube.com/watch?v=TsBcex3M2Xo&list=PL8CN8XjdSyu0TdNKo9U9sF1RL7NB3_0mh
    On
    Off
    Off
    ontimestudios.com
    On
    Off
    Off
    ontimerovideo.com
    On
    Off
    Off
    badchen.com
    On
    Off
    Off
    ebay.com/
    On
    On
    On
    offshorecompany.com
    On
    On
    On
    offshorecompany.com/company/israel-llc/
    On
    On
    On
    wikipedia.org
    On
    On
    On
    ravkavonline.co.il
    On
    On
    On
    tunnelbear.com
    On
    On
    On
    citiprivatepass.com
    On
    On
    On
    docs.google.com
    On
    On
    On
    play.google.com
    On
    On
    On
    myjewishcolorado.org
    On
    On
    On
    hillelacademyofdenver.com/
    On
    On
    On
    wikkipedia.com
    On
    On
    On
    productforums.google.com
    On
    On
    On
    ultrasurf.us
    On
    On
    On
    stackoverflow.com
    On
    On
    On
    tutorialpoint.com
    On
    On
    On
    Dec 29, 2019 12:23 AM
    

    对不起我的有限

    • 2

相关问题

  • Windows CMD 将 PATH 变量重置为默认值

  • Windows 无法重新启动,无法访问任务管理器或启动某些程序

  • 如何创建脚本来监听内容变化并一直接触父文件夹?

  • 在不删除任何文件的情况下重置 Windows 安装的命令是什么

  • Windows 2016 不会运行 .bat 文件

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve