我有成千上万的列和行的数据文件。我要删除实际上是行计数器的第一列。我在linux中使用了以下命令:
cut -d " " -f 2- input.txt > output.txt
但我的输出没有任何变化。有谁知道为什么它不起作用,我该怎么办?
这是我的输入文件的样子:
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
.
.
.
我希望我的输出看起来像这样:
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
但是它将删除第一行而不是第一列。
有人可以指导我吗?
@Karafka我有CSV文件,因此我添加了“,”分隔符(您可以将其替换为
cut -d"," -f2- input.csv > output.csv
然后,我使用循环遍历目录内的所有文件
# 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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句