How to delete header (first row) and first column from multiple CSV files
I have several of csv files, I want to remove the first row (header) and first column as well. This is my code, but it overwrites the original files with no content inside:
for x in *.csv; do sed '1d' $x | cut -d, -f 1 > "$x"; done Help would be highly appreciated. |
You could use a temporary filename if you can think of one that's definitely not in use.
[code] sed '1d' $x | cut -d, -f 1 > replace_$x && mv replace_$x $x [//code] |
Hi linosaurusroot,
the code: for x in *.csv; do sed '1d' $x | cut -d, -f 1 > replace_$x && mv replace_$x $x ; done is deleting the files and only retain the column 1 , I am intending to cut |
Thank you: This works:
for x in *.csv; do sed '1d' $x| awk 'BEGIN{FS=OFS=","}{$1="";sub(",","")}1' > rippe_$x && mv rippe_$x $x ; done |
I used your code from the earlier post
Code:
cut -d, -f 1 Code:
cut -d, -f 2- |
if awk:
Code:
awk ' BEGIN{FS=OFS=","}NR>1{$1="";sub(",","");print}' |
Or even
Code:
awk ' BEGIN{FS=OFS=","}NR>1{sub(/[^,]+,/,"");print}' |
I see no issue with sed either:
Code:
sed -i -e '1d' -e 's/[^,]*,//' *.csv |
Not like you grail to use two "-e" when one would suffice .... :p
|
All times are GMT -5. The time now is 04:26 AM. |