1

Как пронумеровать строки в файле?
grep, sed, regex ?
Только по-проще покажите, потому что нужно для GnuWin32 под виндоус ab
sed, например, там без 'кавычек' работает: sed -i s/string1/string2/g file
Впрочем под linux тоже интересно.

sudo включить компьютер

2

nl входит в coreutils, так что быть должен...
для grep'а ключ -n смотри.
для sed'а через = можно, но не очень красиво получается...

95% процентов проблем находятся между клавиатурой и стулом.

3 (19.02.2013 12:03:53 отредактировано bormant)

Ответ есть в man cat.

+ открыть спойлер
$ echo -e "line\nline\nline" | cat -n
     1    line
     2    line
     3    line

4

Не совсем сформулировал задачу, нужно в готовый текст в начало строк нумерация, но наверное это сложнее

sudo включить компьютер

5 (19.02.2013 12:47:42 отредактировано Linux777)

semiono пишет:

Не совсем сформулировал задачу, нужно в готовый текст в начало строк нумерация, но наверное это сложнее

нет, не сложно, вот на примере готового файла hosts.allow

+ открыть спойлер

root@monitoring:/etc# cat hosts.allow
# /etc/hosts.allow: list of hosts that are allowed to access the system.
#                   See the manual pages hosts_access(5) and hosts_options(5).
#
# Example:    ALL: LOCAL @some_netgroup
#             ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
#
# If you're going to protect the portmapper use the name "portmap" for the
# daemon name. Remember that you can only use the keyword "ALL" and IP
# addresses (NOT host or domain names) for the portmapper, as well as for
# rpc.mountd (the NFS mount daemon). See portmap(8) and rpc.mountd(8)
# for further information.

теперь номеруем строчки

root@monitoring:/etc# cat hosts.allow | cat -n
     1  # /etc/hosts.allow: list of hosts that are allowed to access the system.
     2  #                   See the manual pages hosts_access(5) and hosts_options(5).
     3  #
     4  # Example:    ALL: LOCAL @some_netgroup
     5  #             ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
     6  #
     7  # If you're going to protect the portmapper use the name "portmap" for the
     8  # daemon name. Remember that you can only use the keyword "ALL" and IP
     9  # addresses (NOT host or domain names) for the portmapper, as well as for
    10  # rpc.mountd (the NFS mount daemon). See portmap(8) and rpc.mountd(8)
    11  # for further information.

как видно, все пронумеровалось. но есть и второй способ. открой любой vi-подобный редактор. Например vim и напиши : set number. результат тот же самый увидешь. пример

  1 # /etc/hosts.allow: list of hosts that are allowed to access the system.
  2 #                   See the manual pages hosts_access(5) and hosts_options(5).
  3 #
  4 # Example:    ALL: LOCAL @some_netgroup
  5 #             ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
  6 #
  7 # If you're going to protect the portmapper use the name "portmap" for the
  8 # daemon name. Remember that you can only use the keyword "ALL" and IP
  9 # addresses (NOT host or domain names) for the portmapper, as well as for
10 # rpc.mountd (the NFS mount daemon). See portmap(8) and rpc.mountd(8)
11 # for further information.
12 #
13
~
~
~
~
~
:set number

добрый человек:)
Linux admin PC 3.8.0-23-generic #34-Ubuntu SMP Wed May 29 20:22:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
system admin of unix. i like my job. also i like to catch fish and many other things and english too.
Хочу на пляж)

6 (19.02.2013 13:20:56 отредактировано -=Serj=-)

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import sys

if len(sys.argv) != 2:
    sys.stderr.write("Usage: %s <file>\n" % sys.argv[0])
    raise SystemExit(1)
fname = sys.argv[1]
with open(fname, 'r') as f:
    lines = f.readlines()
n = 0
with open(fname, 'w') as f:
    for line in lines:
        n += 1
        f.write(str(n) + '\t' + line)

Правда, с форматированием лучше бы.
Можно собрать бинарник хоть под Linux, хоть под Windows:)

Ну, или man sed.

Да, у меня Ubuntu.
Нет, не глючит.

7 (22.02.2013 01:33:18 отредактировано semiono)

cat -n file.txt > new.txt

Да, у меня Ubuntu.
Нет, не глючит.

ag

sudo включить компьютер