0

我有一个 out.txt 我想读入列而不是行。我想将第 1-5 行变成一列,将 6-10 变成一列,等等。谁能指出我正确的方向?

diff -r ./playground2/GN_GLENDALE_BILLS_130911_113722.txt ./playground/GN_GLENDALE_BILLS_130911_113722.txt
22c22
< N4*MCDONALDS*KY*40512~^M
---
> N4*LEXINGTON*KY*40512~^M
diff -r ./playground2/GN_GLENDALE_BILLS_130911_113723.txt ./playground/GN_GLENDALE_BILLS_130911_113723.txt
22c22
< N4*MCDONALDS*KY*40512~^M
---
> N4*LEXINGTON*KY*40512~^M
diff -r ./playground2/GN_GLENDALE_BILLS_130911_113725.txt ./playground/GN_GLENDALE_BILLS_130911_113725.txt
22c22
< N4*MCDONALDS*KY*40512~^M
---
> N4*LEXINGTON*KY*40512~^M
4

1 回答 1

0

假设文件有许多行可以被 5 整除(或者任何剩余的行都将被忽略),这应该可以正常工作:

filein=out.txt
fid=15                        #file identifier
nlines=`cat $filein | wc -l`  #count number of lines in file
eval "exec $fid<$filein"
for cnt in $(seq 1 $((nlines/5))); do
   read <&$fid line1
   read <&$fid line2
   read <&$fid line3
   read <&$fid line4
   read <&$fid line5
   echo $line1 $line2 $line3 $line4 $line5
done
eval "exec $fid<&-"

基本上,它只是为文件中 1/5 的行数执行一个 for 循环,一次读取 5 行并一次将它们全部吐出。

于 2013-09-13T21:40:10.170 回答