How to delete the first column ( which is in fact row names) from a data file in linux?

前端 未结 5 1888
失恋的感觉
失恋的感觉 2021-01-01 11:10

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          


        
5条回答
  •  攒了一身酷
    2021-01-01 11:31

    @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
    

提交回复
热议问题