text - NEWBIE — Renumbering line numbers in .txt file -
i have simple text file has been edited looks this:
1,47:26:23n,121:15:10w,1641m,t,3 queens mtn, 2,48:01:19n,119:56:12w,367m,t,alta lake, 4,48:40:19n,121:35:35w,1705m,t,anderson butte, 5,48:36:52n,122:15:58w,736m,t,anderson mtn, 6,48:55:13n,120:13:41w,2518m,t,andrew peak, 8,47:58:06n,119:55:15w,907m,t,arbuckle mtn, 11,48:39:49n,121:31:14w,2138m,t,bacon peak, 12,48:46:38n,121:48:48w,3176m,t,baker mtn, 13,48:57:12n,120:15:34w,2419m,t,bald mtn,
i re-edit file reads:
1,47:26:23n,121:15:10w,1641m,t,3 queens mtn, 2,48:01:19n,119:56:12w,367m,t,alta lake, 3,48:40:19n,121:35:35w,1705m,t,anderson butte, 4,48:36:52n,122:15:58w,736m,t,anderson mtn, 5,48:55:13n,120:13:41w,2518m,t,andrew peak, 6,47:58:06n,119:55:15w,907m,t,arbuckle mtn, 7,48:39:49n,121:31:14w,2138m,t,bacon peak, 8,48:46:38n,121:48:48w,3176m,t,baker mtn, 9,48:57:12n,120:15:34w,2419m,t,bald mtn,
any appreciated (and sorry if obvious question, after several attempts i'm not making progress).
thanks chris
# solution 1
paste -d, <(seq $(wc -l <input.txt)) <(cut -d, -f 2- input.txt)
# solution 2
awk -f, -vofs=, '{$1=nr}1' input.txt
# result
1,47:26:23n,121:15:10w,1641m,t,3 queens mtn, 2,48:01:19n,119:56:12w,367m,t,alta lake, 3,48:40:19n,121:35:35w,1705m,t,anderson butte, 4,48:36:52n,122:15:58w,736m,t,anderson mtn, 5,48:55:13n,120:13:41w,2518m,t,andrew peak, 6,47:58:06n,119:55:15w,907m,t,arbuckle mtn, 7,48:39:49n,121:31:14w,2138m,t,bacon peak, 8,48:46:38n,121:48:48w,3176m,t,baker mtn, 9,48:57:12n,120:15:34w,2419m,t,bald mtn,
Comments
Post a Comment