开发者

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

开发者 https://www.devze.com 2023-01-23 00:15 出处:网络
I wonder wheth开发者_如何转开发er there is a way using awk to number the lines according to a field. For example,

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

精彩评论

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