-1

我有一个经过编辑的简单文本文件,如下所示:

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,

我想重新编辑此文件,使其内容为:

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,

任何帮助将不胜感激(如果这是一个非常明显的问题,很抱歉,但经过几次尝试我没有取得太大进展)。

谢谢克里斯

4

1 回答 1

1

# 解决方案 1

paste -d, <(seq $(wc -l <input.txt)) <(cut -d, -f 2- input.txt)

# 解决方案 2

awk -F, -vOFS=, '{$1=NR}1' input.txt

# 结果

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,
于 2013-04-09T00:57:40.737 回答