如何根据文件中的行号提取特定行 [英] How to extract specific rows based on row number from a file
问题描述
我正在研究一个RNA-Seq数据集,该数据集由大约24000行(基因)和1100列(样本)组成,并用制表符分隔.为了进行分析,我需要选择一个特定的基因集.如果有一种基于行号提取行的方法,那将非常有帮助?对我而言,用这种方式比使用基因名称更容易.
I am working on a RNA-Seq data set consisting of around 24000 rows (genes) and 1100 columns (samples), which is tab separated. For the analysis, I need to choose a specific gene set. It would be very helpful if there is a method to extract rows based on row number? It would be easier that way for me rather than with the gene names.
下面是数据(4X4)的示例-
Below is an example of the data (4X4) -
gene样本1样本2样本3
gene Sample1 Sample2 Sample3
A1BG 5658 5897 6064
A1BG 5658 5897 6064
AURKA 3656 3484 3415
AURKA 3656 3484 3415
AURKB 9479 105429895
AURKB 9479 10542 9895
例如,我要第一行,第三行和第四行没有特定的模式
From this, say for example, I want row 1, 3 and4, without a specific pattern
我还问过 biostars.org .
推荐答案
您可以使用for循环来构建 sed
选项,如下所示:
You may use a for-loop to build the sed
options like below
var=-n
for i in 1 3,4 # Put your space separated ranges here
do
var="${var} -e ${i}p"
done
sed $var filename
Note: In any case the requirement mentioned here would still be pain as it involves too much typing.
这篇关于如何根据文件中的行号提取特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!