Вот короткий скрипт Python, который делает то, что ты хочешь. Использование простое: укажите файл, номер, с которого начинается строка, и номер, который вы хотите видеть вместо него
Демонстрация:
bash-4.3$ cat data.txt 2 19/10/16 15:30 some other line 1 20/10/16 12:00 take car in the garage joe's garage 3 17/10/16 5:30 another one bash-4.3$ python renumber.py data.txt 1 15 ['renumber.py', 'data.txt', '1', '15'] bash-4.3$ cat data.txt 2 19/10/16 15:30 some other line 15 20/10/16 12:00 take car in the garage joe's garage 3 17/10/16 5:30 another one
Код:
import sys
import os
print(sys.argv)
with open(sys.argv[1]) as inputfile:
with open('/tmp/temp.text','w') as tempfile:
for line in inputfile:
old = line.strip().split()
if old[0] == sys.argv[2]:
old[0] = sys.argv[3]
line = ' '.join(old) + '\n'
tempfile.write(line)
os.rename('/tmp/temp.text',sys.argv[1])