8

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
7

create new file with line numbers and just get rid of old one

awk '{printf "%s,%s\n", NR,$0}' input.txt > new.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.