gpt4 book ai didi

linux - UNIX sed 命令不删除 cat 输出中的空格

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:48:04 25 4
gpt4 key购买 nike

我有一个文件如下。

Hi this is first line
this is second line
this is third line

预期是:

Hi this is first line
this is second line
this is third line

我用的是

cat file.txt | sed 's/ //g'

返回,

Hi this is first line
this is second line
this is third line

最佳答案

对于可移植的 sed 命令,使用这个:

sed 's/^[[:blank:]]*//' file

[[:blank:]] 匹配空格或制表符。

编辑:使用 awk 删除所有空格:

awk '{$1=$1}1' OFS= file

或 sed:

sed 's/[[:blank:]]*//g' file

关于linux - UNIX sed 命令不删除 cat 输出中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22204150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com