开发者

How to number the lines according to a field with awk?

I wonder wheth开发者_如何转开发er there is a way using awk to number the lines according to a field. For example,

Input

2334 332
2334 546
2334 675
7890 222
7890 134
234  45
.
.
.

Based on the 1st field, I would have the following output

Output

1 2334 332
1 2334 546
1 2334 675
2 7890 222
2 7890 134
3 234  45
.
.
.

I would be grateful for your help.

Cheers,

T


here's how,

awk '!a[$1]++{c++}{print c, $0}' file
1 2334 332
1 2334 546
1 2334 675
2 7890 222
2 7890 134
3 234  45


awk 'last != $1 { line = line + 1 } { last = $1; print line, $0 }'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜