awk 不打印换行符 [英] awk without printing newline

查看:93
本文介绍了awk 不打印换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在每次迭代中并排打印变量 sum/NR.我们如何避免 awk 在每次迭代中打印换行符?在我的代码中,默认情况下每次迭代都会打印换行符

I want the variable sum/NR to be printed side-by-side in each iteration. How do we avoid awk from printing newline in each iteration ? In my code a newline is printed by default in each iteration

for file in cg_c ep_c is_c tau xhpl
printf "
 $file" >> to-plot.xls
    for f in 2.54 1.60 800 
        awk '{sum+=$3}; END  {print  sum/NR}' ${file}_${f}_v1.xls >> to-plot-p.xls
    done
done

我希望输出看起来像这样

I want the output to appear like this

cg_c ans1  ans2  ans3  
ep_c ans1  ans2  ans3 
is_c ans1  ans2  ans3
tau  ans1  ans2  ans3 
xhpl ans1  ans2  ans3

我现在的输出是这样的

**cg_c**
ans1
ans2
ans3
**ep_c**
ans1
ans2
ans3
**is_c**
ans1
ans2
ans3
**tau**
ans1
ans2
ans3
**xhpl**
ans1
ans2
ans3

推荐答案

awk '{sum+=$3};END {printf "%f",sum/NR}' ${file}_${f}_v1.xls >>to-plot-p.xls

print 默认会插入换行符.您不希望这种情况发生,因此请改用 printf.

print will insert a newline by default. You dont want that to happen, hence use printf instead.

这篇关于awk 不打印换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆