假设文件有7行,1-3行变成1行,4-6行变成一行
#!/bin/bash
n=1
cat $1 | while read line
do
n1=$[$n%3]
if [ $n1 -eq 0 ]
then
echo "$line"
else
echo -n "$line"
fi
n=$[$n+1]
done
echo -e ""
执行结果
[root@localhost shell]# cat 42.txt
1
2
3aaa
4222
5 fsfs
6>/er[we
7777
[root@localhost shell]# sh 42.sh 42.txt
1 2 3aaa
4222 5 fsfs 6>/er[we
7777
[root@localhost shell]#