Skip to main content
Added more info
Source Link
heemayl
  • 58.1k
  • 9
  • 129
  • 144

You can also try Python:

#!/usr/bin/env python2
with open('file.txt') as f:
    check = 0
    for line in f:
        if int(line.split()[0]) == check + 1:
            check = int(line.split()[0])
            print line.rstrip()
        else:
            check = int(line.split()[0])
            print int(line.split()[0]) - 1, 'NA'
            print line.rstrip()
    print int(line.split()[0]) + 1, 'NA'
    print int(line.split()[0]) + 2, 'NA'

Here we are comparing the line number int(line.split()[0]) with check + 1, we have set initial value of check as 0. If the values are equal we have printed the line, otherwise we have printed the desired content i.e. missing line number and NA. The last two lines are used to print the 11th and 12th lines.

You can also try Python:

#!/usr/bin/env python2
with open('file.txt') as f:
    check = 0
    for line in f:
        if int(line.split()[0]) == check + 1:
            check = int(line.split()[0])
            print line.rstrip()
        else:
            check = int(line.split()[0])
            print int(line.split()[0]) - 1, 'NA'
            print line.rstrip()
    print int(line.split()[0]) + 1, 'NA'
    print int(line.split()[0]) + 2, 'NA'

You can also try Python:

#!/usr/bin/env python2
with open('file.txt') as f:
    check = 0
    for line in f:
        if int(line.split()[0]) == check + 1:
            check = int(line.split()[0])
            print line.rstrip()
        else:
            check = int(line.split()[0])
            print int(line.split()[0]) - 1, 'NA'
            print line.rstrip()
    print int(line.split()[0]) + 1, 'NA'
    print int(line.split()[0]) + 2, 'NA'

Here we are comparing the line number int(line.split()[0]) with check + 1, we have set initial value of check as 0. If the values are equal we have printed the line, otherwise we have printed the desired content i.e. missing line number and NA. The last two lines are used to print the 11th and 12th lines.

Source Link
heemayl
  • 58.1k
  • 9
  • 129
  • 144

You can also try Python:

#!/usr/bin/env python2
with open('file.txt') as f:
    check = 0
    for line in f:
        if int(line.split()[0]) == check + 1:
            check = int(line.split()[0])
            print line.rstrip()
        else:
            check = int(line.split()[0])
            print int(line.split()[0]) - 1, 'NA'
            print line.rstrip()
    print int(line.split()[0]) + 1, 'NA'
    print int(line.split()[0]) + 2, 'NA'