bash - adding a new column as line number in a csv file - Ask Ubuntu
i created csv file forgot add line number first column. fastest way (for 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 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
create new file line numbers , rid of old one
awk '{printf "%s,%s\n", nr,$0}' input.txt > new.txt
Comments
Post a Comment