【发布时间】:2015-02-24 11:56:17
【问题描述】:
这类似于
How to add a column from a file to another file
但在这种情况下,我只想使用 5 列文件 B 中的第 5 列。两个制表符分隔,长度相同。有没有办法用 awk ,粘贴或其他东西来做到这一点?
file A
str str str
str2 str2 str2
fileB
as at aw ay ao
re rt ty yu ui
oFile
str str str ao
str2 str2 str2 ui
ExtraInfo,我正在创建一些类似的文件,我只想要其中的一列。示例完整脚本,obv 不正确;
for pheno in $(seq 1 $nbGroups)
do
batch=$(sed -n $pheno'p' $Names)
## do some stuff to $batch
if [ $pheno=1 ]
then
awk '{ print $1, $1, $5}' $batch > $bDir"NewFile"
fi
if [ $pheno>1 ]
then
awk '{ print $5}' $batch >> $bDir"File"
fi
done
【问题讨论】:
-
发布一个示例以及预期的输出。
-
是的,谢谢。
-
不清楚第二个 sn-p 与您的问题有何关系 - 没有明显的尝试将多个文件中的列组合在一起。
-
我知道它不起作用。这就是我问一个问题的原因。没有任何明显的努力是粗鲁和不正确的。
-
你真的在使用 bash 吗?如果是这样,数字测试应该是
((pheno==1))和((pheno>1))。如果您受限于 Posix shell 功能,则需要[ $pheno -eq 1 ]和[ $pheno -lt 1 ]。内置的test(也拼写为[)保留=和>用于字符串比较,并要求它们是单独的单词(即用空格包围;另外,因为<和>是shell 元字符,它们需要被引用。所有这些都使得[[和((构造更不容易出错。
标签: bash