小编Sar*_*mar的帖子

如何正确使用 cut 从 shell 脚本中的字符串中获取所需的输出?

#!/bin/bash
list="john,do not target
martin,unknown"

for i in $list; do
     name=`echo ${i} | cut -f1 -d','`
     value=`echo ${i} | cut -f2 -d','`
     echo $value
done
Run Code Online (Sandbox Code Playgroud)

由于中间的空白不以我得到的上述输出为目标,

do
not
target
unknown
Run Code Online (Sandbox Code Playgroud)

我想要的输出是:

do not target
unknown
Run Code Online (Sandbox Code Playgroud)

bash shell cut

1
推荐指数
2
解决办法
82
查看次数

标签 统计

bash ×1

cut ×1

shell ×1