gpt4 book ai didi

linux - 每第 n 行将行转换为列

转载 作者:太空宇宙 更新时间:2023-11-04 04:11:41 26 4
gpt4 key购买 nike

我有一个 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

最佳答案

假设文件的行数可以被 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 行并一次将它们全部吐出。

关于linux - 每第 n 行将行转换为列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18794730/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com