首页 > 解决方案 > 循环时使用选项卡正确创建文件

问题描述

我有这个命令行:

while read line
do 
echo $line >> Ho
grep -c "0/1/0" file_$line\.hwe >> Ho
done < my_file

这会给我这样的东西:

ID1
689
ID2
747
etc.

我想知道如何制作循环,以便 ls 和 grep 命令打印在同一行而不是不同的行上。这是我想要获得的:

ID1  689
ID2  747
etc.

有什么线索吗?谢谢!

标签: bash

解决方案


真的,只是:

while IFS= read -r line; do 
   echo "$line"$'\t'"$(grep -c "0/1/0" "file_$line.hwe")"
done < my_file >> Ho

或者可能:

while IFS= read -r line; do 
   printf "%s\t%s\n" "$line" "$(grep -c "0/1/0" "file_$line.hwe")"
done < my_file >> Ho

但你仍然可以:

while IFS= read -r line; do 
   echo "$line" 
   grep -c "0/1/0" "file_$line.hwe"
done < my_file |
paste -d $'\t' - - >> Ho

推荐阅读