所以我是bash linux的新手,我正在尝试修复.txt文件。
我有一个.txt文件,看起来像这样:
blueberry, "yummy", 12345, "I love fruit and eating apples"
blueberry, "tasty", 4455, "fruit is good for you"
blueberry, "yum", 109833, "I go crazy for fruit"
blueberry, "wooohh", 1347672, "I love fruit and
eating apples"
blueberry, "yummy yummy", 1023433, "I love fruit more than my dog"
blueberry, "yummy", 12345, "I love fruit and eating apples"
blueberry, "something good to eat", 42, "fruit is the
greatest thing EVER"
blueberry, "tasty", 4455, "fruit is good for you"
blueberry, "yum", 109833, "I go crazy for fruit"
我想创建一个如下所示的新.txt文件:
blueberry, "yummy", 12345, "I love fruit and eating apples"
blueberry, "tasty", 4455, "fruit is good for you"
blueberry, "yum", 109833, "I go crazy for fruit"
blueberry, "wooohh", 1347672, "I love fruit and eating apples"
blueberry, "yummy yummy", 1023433, "I love fruit more than my dog"
blueberry, "yummy", 12345, "I love fruit and eating apples"
blueberry, "something good to eat", 42, "fruit is the greatest thing EVER"
blueberry, "tasty", 4455, "fruit is good for you"
blueberry, "yum", 109833, "I go crazy for fruit"
(所以两条线上的随机句子重新组合在一起)
到目前为止,我尝试使用echo如此:
while read p; do #for every line in the .txt file
if[[ $p == "blueberry"* ]] #if the line starts with 'blueberry'
echo -n "$p" >> newfruit.txt #add the line to newfruit.txt without a new line
else
echo " $p" >> newfruit.txt #add to the current line
fi
done <fruit.txt
但它只返回完全相同的.txt文件 我也尝试过使用printf和echo -e,结果相同
任何建议或提示将不胜感激!谢谢!
答案 0 :(得分:0)
awk '{printf $0}/"$/{printf "\n"}' fruit.txt
打印每一行没有换行符。 如果行以“,打印换行符
结束