Skip to main content
Rollback to Revision 3
Source Link
Kaz
  • 8.9k
  • 2
  • 31
  • 52

I have a file with about 10k lines. I would like to prependadd the line numbers to the first column, but in such a way as to repeat the prependedline numbers 1 for the first 100 lines of input data, then prepend the 2 to the second 100 lines, and so on-100.

Example input: For example,

1 12313
2 3434
4233
< 96 more lines of numbers. 
. 
.
100 >4233
1 24523
< 97 more lines of numbers... >
4543543
.
.
.     

Example output:

1 12313
1100 34344543543
1 4233
< 96 more lines of numbers... >
2 24523.
< 97 more. lines of numbers... >
2 4543543
3 < ...etc>100

How could I do it using grepgrep or awkawk?

Using awk, I managed to print the line numbers, but without any repeating: using awk

awk '{ print NR, $1 }' p2.dat > p3.dat

I have a file with 10k lines. I would like to prepend line numbers to the first column, but in such a way as to repeat the prepended 1 for the first 100 lines of input data, then prepend the 2 to the second 100 lines, and so on.

Example input:

12313
3434
4233
< 96 more lines of numbers... >
24523
< 97 more lines of numbers... >
4543543
.
.
.     

Example output:

1 12313
1 3434
1 4233
< 96 more lines of numbers... >
2 24523
< 97 more lines of numbers... >
2 4543543
3 < ...etc>

How could I do it using grep or awk?

Using awk, I managed to print the line numbers, but without any repeating:

awk '{ print NR, $1 }' p2.dat > p3.dat

I have a file with about 10k lines. I would like to add the line numbers to the first column, but in a way to repeat the line numbers 1-100. For example,

1 12313
2 3434
. 
. 
.
100 4233
1 24523
.
.
.
100 4543543
1
.
.
.     
100

How could I do it using grep or awk? I managed to print the line numbers, but without repeating using awk

awk '{ print NR, $1 }' p2.dat > p3.dat
Clarified language, as per OP's comments.
Source Link

I have a file with 10k lines. I would like to add theprepend line numbers to the first column, but in such a way as to repeat the line numberprepended 1 for the first 100 lines of input data, then line number2prepend the 2 to the second 100 lines, and so on. For example,

Example input:

1 12313
1 3434
.4233
< 96 more lines of numbers.
 .
1. 4233>
2 24523
< 97 more lines of numbers.
 .
 .
2 4543543>
34543543
.
.
.     
3

Example output:

1 12313
1 3434
1 4233
< 96 more lines of numbers... >
2 24523
< 97 more lines of numbers... >
2 4543543
3 < ...etc>

How could I do it using grepgrep or awkawk?

Using awk, I managed to print the line numbers, but without any repeating using awk:

awk '{ print NR, $1 }' p2.dat > p3.dat

I have a file with 10k lines. I would like to add the line numbers to the first column, but in a way to repeat the line number 1 for the first 100 lines, then line number2 to the second 100 lines, and so on. For example,

1 12313
1 3434
.
.
 .
1 4233
2 24523
.
 .
 .
2 4543543
3
.
.
.     
3
.
.
.

How could I do it using grep or awk? I managed to print the line numbers, but without repeating using awk

awk '{ print NR, $1 }' p2.dat > p3.dat

I have a file with 10k lines. I would like to prepend line numbers to the first column, but in such a way as to repeat the prepended 1 for the first 100 lines of input data, then prepend the 2 to the second 100 lines, and so on.

Example input:

12313
3434
4233
< 96 more lines of numbers... >
24523
< 97 more lines of numbers... >
4543543
.
.
.     

Example output:

1 12313
1 3434
1 4233
< 96 more lines of numbers... >
2 24523
< 97 more lines of numbers... >
2 4543543
3 < ...etc>

How could I do it using grep or awk?

Using awk, I managed to print the line numbers, but without any repeating:

awk '{ print NR, $1 }' p2.dat > p3.dat
added 15 characters in body
Source Link

I have a file with about 10k lines. I would like to add the line numbers to the first column, but in a way to repeat the line numbersnumber 1-100 for the first 100 lines, then line number2 to the second 100 lines, and so on. For example,

1 12313
21 3434
.
.
.
1001 4233
12 24523
.
.
.
1002 4543543
13
.
.
.     
1003
.
.
.

How could I do it using grep or awk? I managed to print the line numbers, but without repeating using awk

awk '{ print NR, $1 }' p2.dat > p3.dat

I have a file with about 10k lines. I would like to add the line numbers to the first column, but in a way to repeat the line numbers 1-100. For example,

1 12313
2 3434
.
.
.
100 4233
1 24523
.
.
.
100 4543543
1
.
.
.     
100

How could I do it using grep or awk? I managed to print the line numbers, but without repeating using awk

awk '{ print NR, $1 }' p2.dat > p3.dat

I have a file with 10k lines. I would like to add the line numbers to the first column, but in a way to repeat the line number 1 for the first 100 lines, then line number2 to the second 100 lines, and so on. For example,

1 12313
1 3434
.
.
.
1 4233
2 24523
.
.
.
2 4543543
3
.
.
.     
3
.
.
.

How could I do it using grep or awk? I managed to print the line numbers, but without repeating using awk

awk '{ print NR, $1 }' p2.dat > p3.dat
deleted 21 characters in body
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264
Loading
tags
Link
countermode
  • 7.8k
  • 5
  • 34
  • 59
Loading
Source Link
Loading