如何使用shell从txt读取一些数据

问题描述 投票:0回答:1

我在Linux中有这样的文本文件:

//data.txt
    a
    e
    i
    o
    u

并且想要使5个txt文件相对于上述字符,输出看起来像这样:

Created a.txt
Created e.txt
Created i.txt
Created o.txt
Created u.txt

但是我不确定我做错了什么,它会一直呆在那里等待我的输入。

#!/bin/bash
x=$data.txt | tr -d '\r'
for((i=0;i<${#x};i++));
do
   y=${x,i,1}
   touch $y.txt
   echo "Created $y.txt"
done
linux shell
1个回答
0
投票

您可以使用反引号的功能来在换行符上进行分割。

© www.soinside.com 2019 - 2024. All rights reserved.