adding a new column as line number in a csv file
6,447
create new file with line numbers and just get rid of old one
awk '{printf "%s,%s\n", NR,$0}' input.txt > new.txt
Related videos on Youtube
Author by
Mona Jalal
contact me at [email protected] I am a 5th-year computer science Ph.D. Candidate at Boston University advised by Professor Vijaya Kolachalama in computer vision as the area of study. Currently, I am working on my proposal exam and thesis on the use of efficient computer vision and deep learning for cancer detection in H&E stained digital pathology images.
Updated on September 18, 2022Comments
-
Mona Jalal over 1 year
I created a csv file but forgot to add line number as the first column. What is the fastest way to do this (for a large file)?
262145,umbrella,umbrella,carrot,carrot,carrot,carrot,person,person,person,person,person,person,person,person,person,person,person,person,umbrella,carrot,carrot,carrot,carrot,carrot,carrot,carrot,carrot,person,umbrella,carrot,person,carrot 262146,person,skis,backpack 524291,dog,dog,person,frisbee 393223,toothbrush,person 393224,tie,person,person,person,person,person 524297,person,person,person,bear 393227,person,skateboard 131084,motorcycle,person 393230,person,skis 524311,chair,person,remote 393241,frisbee,person,person,person,person,person,person,person,person,person,car,car,person,car,car,person,person,person 524314,car,person,person,teddy bear,car,handbag,cell phone,car,handbag,teddy bear 262171,boat,person,person,person,person,person,person,boat,person 131101,umbrella,person,person,backpack,handbag,person 524320,tie,person,person,suitcase,person
I want something like:
1,262145,umbrella,umbrella,carrot,carrot,carrot,carrot,person,person,person,person,person,person,person,person,person,person,person,person,umbrella,carrot,carrot,carrot,carrot,carrot,carrot,carrot,carrot,person,umbrella,carrot,person,carrot 2,262146,person,skis,backpack