在执行循环时正确创建带有标签的文件

问题描述 投票:0回答:1

我有此命令行:

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.

任何线索?谢谢!

M

bash
1个回答
0
投票

真的,只是:

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
© www.soinside.com 2019 - 2024. All rights reserved.