如何从Linux的数据文件中删除第一列(实际上是行名)? [英] How to delete the first column ( which is in fact row names) from a data file in linux?
问题描述
我的数据文件有成千上万的列和行.我要删除实际上是行计数器的第一列.我在Linux中使用了以下命令:
I have data file with many thousands columns and rows. I want to delete the first column which is in fact the row counter. I used this command in linux:
cut -d " " -f 2- input.txt > output.txt
,但我的输出没有任何变化.有人知道为什么它不起作用,我该怎么办?
but nothing changed in my output. Does anybody knows why it does not work and what should I do?
这是我的输入文件的样子:
This is what my input file looks like:
col1 col2 col3 col4 ...
1 0 0 0 1
2 0 1 0 1
3 0 1 0 0
4 0 0 0 0
5 0 1 1 1
6 1 1 1 0
7 1 0 0 0
8 0 0 0 0
9 1 0 0 0
10 1 1 1 1
11 0 0 0 1
.
.
.
我希望我的输出看起来像这样:
I want my output look like this:
col1 col2 col3 col4 ...
0 0 0 1
0 1 0 1
0 1 0 0
0 0 0 0
0 1 1 1
1 1 1 0
1 0 0 0
0 0 0 0
1 0 0 0
1 1 1 1
0 0 0 1
.
.
.
我还尝试了sed
命令:
sed '1d' input.file > output.file
但是它将删除第一行而不是第一列.
But it deletes the first row not the first column.
有人可以引导我吗?
推荐答案
@Karafka我有CSV文件,因此我添加了,"分隔符(您可以用自己的分隔符替换
@Karafka I had CSV files so I added the "," separator (you can replace with yours
cut -d"," -f2- input.csv > output.csv
然后,我使用循环遍历目录内的所有文件
Then, I used a loop to go over all files inside the directory
# files are in the directory tmp/
for f in tmp/*
do
name=`basename $f`
echo "processing file : $name"
#kepp all column excep the first one of each csv file
cut -d"," -f2- $f > new/$name
#files using the same names are stored in directory new/
done
这篇关于如何从Linux的数据文件中删除第一列(实际上是行名)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!