【问题标题】:Print multiple strings to a file with the breakline in bat使用 bat 中的断线将多个字符串打印到文件中
【发布时间】:2021-02-11 03:41:20
【问题描述】:

我想向一个文本文件(带有绝对路径)添加许多字符串(一个在另一个之下。)我想我已经使用这个例子找到了解决方案:

echo hello & echo.world

但是当我运行我的程序时,程序只将最后一个字符串添加到文本文件中(即 #127.0.0.1 spclient.wg.spotify.com)。

有人知道解决办法吗?

我的蝙蝠代码:

echo 127.0.0.1 media-match.com & echo.127.0.0.1 adclick.g.doublecklick.net & echo.127.0.0.1 www.googleadservices.com & echo.127.0.0.1 media-match.com & echo.127.0.0.1 adclick.g.doublecklick.net & echo.127.0.0.1 www.googleadservices.com & echo.127.0.0.1 pagead2.googlesyndication.com & echo.127.0.0.1 googleads.g.doubleclick.net & echo.127.0.0.1 pubads.g.doubleclick.net & echo.127.0.0.1 securepubads.g.doubleclick.net & echo.127.0.0.1 www.omaze.com & echo.127.0.0.1 omaze.com & echo.127.0.0.1 bounceexchange.com & echo.127.0.0.1 core.insightexpressai.com & echo.127.0.0.1 content.bitsontherun.com & echo.127.0.0.1 s0.2mdn.net & echo.127.0.0.1 v.jwpcdn.com & echo.127.0.0.1 d2gi7ultltnc2u.cloudfront.net & echo.127.0.0.1 cs283.wpc.teliasoneracdn.net & echo.127.0.0.1 cs126.wpc.teliasoneracdn.net & echo.127.0.0.1 u.scdn.co & echo.127.0.0.1 cs126.wpc.edgecastcdn.net & echo.127.0.0.1 pagead46.l.doubleclick.net & echo.127.0.0.1 pagead.l.doubleclick.net & echo.127.0.0.1 video-ad-stats.googlesyndication.com & echo.127.0.0.1 pagead-googlehosted.l.google.com & echo.127.0.0.1 partnerad.l.doubleclick.net & echo.127.0.0.1 prod.spotify.map.fastlylb.net & echo.127.0.0.1 adserver.adtechus.com & echo.127.0.0.1 na.gmtdmp.com & echo.127.0.0.1 anycast.pixel.adsafeprotected.com & echo.127.0.0.1 ads.pubmatic.com & echo.127.0.0.1 idsync-ext.rlcdn.com & echo.127.0.0.1 www.googletagservices.com & echo.127.0.0.1 googlehosted.l.googleusercontent.com & echo.127.0.0.1 d361oi6ppvq2ym.cloudfront.net & echo.127.0.0.1 gads.pubmatic.com & echo.127.0.0.1 ads-west-colo.adsymptotic.com & echo.127.0.0.1 geo3.ggpht.com & echo.127.0.0.1 showads33000.pubmatic.com & echo.127.0.0.1 crashdump.spotify.com & echo.127.0.0.1 adeventtracker.spotify.com & echo.127.0.0.1 log.spotify.com & echo.127.0.0.1 analytics.spotify.com & echo.127.0.0.1 ads-fa.spotify.com & echo.127.0.0.1 audio-ec.spotify.com & echo.127.0.0.1 sto3.spotify.com & echo.127.0.0.1 audio2.spotify.com & echo.127.0.0.1 http://audio2.spotify.com & echo.127.0.0.1 www.audio2.spotify.com & echo.127.0.0.1 desktop.spotify.com & echo.127.0.0.1 heads-ec.spotify.com & echo.127.0.0.1 open.spotify.com & echo.#127.0.0.1 spclient.wg.spotify.com >> C:\Users\utente\Documents\bersaglio.txt

我用我用c#制作的程序生成了代码,这是代码:

    **using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {


            String n = "\\n", n2;
            String finale = "";

            Console.WriteLine("This little program is used to insert '& echo.'between 2 or more output strings \n \n \nHow many strings do you have?");
            int stringhe = Convert.ToInt16(Console.ReadLine());

            for (int i = 0; i < stringhe; i++)
            {
                
                Console.Clear();
                Console.WriteLine("enter string number " + (i + 1));
                n = Console.ReadLine();
                finale = finale +" & echo." + n;
            }

            Console.WriteLine(finale);

            String terminadebug = Console.ReadLine();

        }
    }
}**

【问题讨论】:

  • 放括号:(echo hello&amp;echo world) &gt;&gt; "file.ext"...

标签: string batch-file


【解决方案1】:

echo. 很有用,因为使用标记(如 2 个空格)在语法上很好。所以,如果你想在脚本中使用“hello world”,很简单:

(
echo. The dolphins in the Australia are pretty cool, they eats cups
echo and a lot of fish. They are "fishes"! Haha.
echo I promise that the weed is still there, I don't use that things.
echo end
) >> "file.txt"

“&gt;&gt;”是“写入...”,如果你想替换所有“&gt;”就像“写入并替换”,这会将文本上的所有内容替换为您放置的内容。

如果你想在那之后阅读文本文件的第二行,使用批处理脚本,我很乐意帮助你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    • 2011-07-10
    • 2018-05-23
    • 2015-01-16
    • 2018-09-27
    • 2014-08-15
    相关资源
    最近更新 更多