我有一个具有以下数据的输入文件:重定向输出到输出文件
one two
three
fish hat
cat hop
我必须写下面的输出文件
one two three
fish hat cat hop
这里是我的代码,我有这么远
#!/bin/bash
#
# input and output files
FILE=$1
FILE2=$2
#checks to see if the input file exists
if [ -f $FILE ];then
echo "file $FILE found!"
else
echo "file $FILE does not exist"
exit 1
fi
#check to see if output file is empty
if [ -s $FILE2 ]; then
echo "$FILE2 already has data!"
exit 1
fi
#Joins every two input lines
while read first; do read second; echo "$firstLine $secondLine";
done < $FILE
cat $FILE &> $FILE2
我得到的输出文件时,我使用cat命令显示的内容打印到控制台但是输出文件。它显示原始输出文件。有人能指出我犯的错误吗?
用GNU sed和你的例子:'sed'1〜2 {N; s/\ n//}'file' – Cyrus