shell读取文件每一行的方式

1、使用read命令读取一行数据

1
2
3
4
while  read myline
do
  echo  "LINE:" $myline
done < datafile.txt

 2、使用read命令读取一行数据

1
2
3
4
cat datafile.txt |  while  read myline
do
  echo  "LINE:" $myline
done

 3、#读取一行数据

1
2
3
4
cat datafile.txt |  while  myline=$(line)
do
  echo  "LINE:" $myline
done

 4、#读取一行数据

1
2
3
4
while  myline=$(line)
do
  echo  "LINE:" $myline
done < datafile.txt

 5、#使用read命令读取变量数据

1
2
3
4
5
6
cat datafile.txt |  while  read paraa parab parac
do
  echo  "PARAA:" $paraa
  echo  "PARAB:" $parab
  echo  "PARAC:" $parac
done

 6、#使用read命令读取变量数据

1
2
3
4
5
6
while  read paraa parab parac
do
  echo  "PARAA:" $paraa
  echo  "PARAB:" $parab
  echo  "PARAC:" $parac
done < datafile.txt

你可能感兴趣的:(Linux工作记录)