如何从批处理变量中删除换行符 [英] How to remove New line character from batch variable

查看:737
本文介绍了如何从批处理变量中删除换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好! 我有一个批处理脚本,当我回显这样的变量时

Good Day All! I have a batch script, and when I echo a variable like this

echo %variable1%

我出去像这样

TestLine1
TestLine2
TestLine3
TestLine4

我的目标是修改此变量以删除所有换行符,以便输出看起来更像

My goal would be to modify this variable to remove all the newline characters so the output would look more like

TestLine1TestLine2TestLine3TestLine4

是否有一种简单的方法可以在不创建文件的情况下执行此操作? 谢谢您的协助.

Is there a simple way to do this without creating files? Thank you for your assistance.

推荐答案

您可以使用命令tr:

cleanedVariable1=$(echo $variable1 | tr -d '\n' )
echo $cleanedVariable1

命令tr删除或翻译字符.选项-d删除给定的字符.在这种情况下,我们将从变量中删除所有新行,并将其分配给新变量.

The command tr removes or translates characters. The option -d removes the given characters. In this case, we are removing all new lines from our variable and assign it to a new variable.

这篇关于如何从批处理变量中删除换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆