Skip to content

Latest commit

 

History

History
34 lines (34 loc) · 339 Bytes

45.md

File metadata and controls

34 lines (34 loc) · 339 Bytes

题目要求

想办法把文本里面每三行内容合并到一行 例如:1.txt内容

1
2
3
4
5
6
7

处理后应该是

1 2 3
4 5 6
7

参考答案

#!/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