【发布时间】:2019-10-21 09:18:38
【问题描述】:
我有一个 shell 脚本,它逐行读取变量的值。我需要从每一行中删除某些字符。
我所拥有的—— $sample_variable -
Data 0 start; 1 ABCD0;2 EFGH0;3 IJKL0;4 MNOP0;5 QRST0;6 end;
我想要什么 -
start
ABCD0
EFGH0
IJKL0
MNOP0
QRST0
end
我写的代码 -
IFS=$';'
for j in $sample_variable
do
j=$j | cut -d ' ' -f3-
echo $j
j=${j// /''}
echo $j
echo $j >> output.txt
done
我正在将输出写入 txt 文件。但是,该文件正在写入 output.txt -
start
1ABCD0
2EFGH0
3IJKL0
4MNOP0
5QRST0
6end
如何删除开头出现的数字?
【问题讨论】:
-
请写出您的预期输出。
-
请对输入和输出文件也使用代码块格式。您发布的代码无效,它不应生成任何输出。
for j in $sample_variable将输入拆分为空格,j=$j | cut -d ' ' -f3-只是设置j=$j,它不输出任何内容,并执行从标准输入读取的cut。可能您打算使用$( ... )命令替换。the file is getting written- 文件是怎么写成这样的?sample_variable的内容是什么? -
@KamilCuk 请看一看。我在帖子中做了一些更改