LINUX.ORG.RU
решено ФорумAdmin

Разбивка файла при перенаправлении вывода.


0

1

Необходимо писать в текстовый файл вывод программы. Вывод очень большой. Можно ли этот вывод по какому-либо условию разбивать на более мелкие файлы, скажем раз в минуту или при достижении определенного размера файла? Пример

someprog > outfile.log
а на выходе:
outfile.log00
outfile.log01
outfile.log02
outfile.log03
...
outfile.logNN



Последнее исправление: kernel32ddl (всего исправлений: 1)

someprog | split -d -b1024 - outfile.log

разобьёт файл по 1024 байта

backbone ★★★★★
()

Спасибо!

А можно как либо разбивать файл по определенному строковому разделителю? Например при появлении строки «<packet>» в XML файле чтобы создавался следующий файл.

kernel32ddl
() автор топика
Ответ на: комментарий от kernel32ddl

А что, help к команде читать уже не модно?

-p pattern
The file is split whenever an input line matches pattern, which
is interpreted as an extended regular expression. The matching
line will be the first line of the next output file. This option
is incompatible with the -b and -l options.

zgen ★★★★★
()
Ответ на: комментарий от zgen

В split которая идет в Ubunte нет таких параметров:

man split

NAME split - split a file into pieces

SYNOPSIS split [OPTION]... [INPUT [PREFIX]]

DESCRIPTION Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is `x'. With no INPUT, or when INPUT is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.

-a, --suffix-length=N use suffixes of length N (default 2)

-b, --bytes=SIZE put SIZE bytes per output file

-C, --line-bytes=SIZE put at most SIZE bytes of lines per output file

-d, --numeric-suffixes use numeric suffixes instead of alphabetic

-l, --lines=NUMBER put NUMBER lines per output file

--verbose print a diagnostic just before each output file is opened

--help display this help and exit

--version output version information and exit

SIZE may be (or may be an integer optionally followed by) one of following: KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y. ....

kernel32ddl
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.