【发布时间】:2023-03-07 15:36:01
【问题描述】:
这是我的 sample.txt 文件,其中包含以下内容
31113 70:54:D2 - a-31003
31114 70:54:D2 - b-31304
31111 4C:72:B9 - c-31303
31112 4C:72:B9 - d-31302
我必须编写 shell 脚本,因为我将前 5 个字符(例如 31113)作为输入 id 传递给其他脚本。为此我已经尝试过这个
#!/bin/sh
filename='sample.txt'
filelines=`cat $filename`
while read -r line
do
id= cut -c-5 $line
echo $id
#code for passing id to other script file as parameter
done < "$filename"
但它不起作用,这给了我错误
cut: 31113: No such file or directory
cut: 70:54:D2 No such file or directory
31114
31111
31112
: No such file or directory
我该怎么做?
【问题讨论】: