shell脚本while-read-line-column.sh
#!/bin/bash
#date:2024/9
#description:while read line
while read line
do
first=$(echo $line | awk -F"," '{print $1}')
second=$(echo $line | awk -F"," '{print $2}')
third=$(echo $line | awk -F"," '{print $3}')
echo "first column is:" $first
echo "second column is:" $second
echo "third column is:" $third
echo
done < /root/test.txt
验证:
[root@patrolagent ~]# cat test.txt
1,11,ztj1
2,22,ztj2
3,33,ztj3
4,44,ztj4
[root@patrolagent ~]# sh while-read-line-column.sh
first column is: 1
second column is: 11
third column is: ztj1
first column is: 2
second column is: 22
third column is: ztj2
first column is: 3
second column is: 33
third column is: ztj3
first column is: 4
second column is: 44
third column is: ztj4
[root@patrolagent ~]#
1565

被折叠的 条评论
为什么被折叠?



