bash - 循环时使用选项卡正确创建文件
问题描述
我有这个命令行:
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.
有什么线索吗?谢谢!
米
解决方案
真的,只是:
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
推荐阅读
- android-studio - “flutter doctor”命令找不到安装在 Android Studio 中的 Flutter 和 Dart 插件
- mysql - Laravel按abs数值查询顺序不起作用
- node.js - 仅通过 NodeJS 一次从网站获取数据
- python - Widget used for infinitely resizable painting in librecad
- php - Symfony 4 Restful API 使用 JWT 和 facebook 登录
- java - 密钥释放事件不起作用 Java Swing
- python - 尝试将图标添加到我的可执行文件中,但仍显示 OSError [errono22]。不知道发生了什么
- javascript - 如何向 acorn 或 esprima 解析器添加关键字
- java - Arraylist:方法不会打印数组中的最后一个元素
- javascript - iCheck - 通过单击链接检查框