Команды с использованием конвейера | Participants
|
- Settings of this translation
- Statistics
- Participants
- Translate into Russian
- Translation result
- 38% translated in draft.
If you do not want to register an account, you can sign in with OpenID.
Piping hot commands | ||
Pipes let programs work together by connecting the output from one to be the input for another. Pipes are built using a vertical bar (|) as the pipe symbol. | Конвейер (pipe) позволяет работать программам вместе, подключая вывод одной программы ко входным данным другой. Конвейер делается с помощью вертикальной черты (|) | |
Say you help your eccentric Aunt Hortense manage her private book collection. You have a file named books containing a list of her holdings, one per line, in the format 'author:title', something like this: | К примеру, Вы хотите помочь эксцентричной тёте Гартензии управлять своей частной коллекцией книг. У Вас есть файл с названиями книг, каждая строка которого имеет вид 'Автор:Заголовок', что-то вроде этого: | |
$ cat books | ||
Carroll, Lewis:Through the Looking-Glass | ||
Shakespeare, William:Hamlet | ||
Bartlett, John:Familiar Quotations | ||
Mill, John Stuart:On Nature | ||
London, Jack:John Barleycorn | ||
Bunyan, John:Pilgrim's Progress, The | ||
Defoe, Daniel:Robinson Crusoe | ||
Mill, John Stuart:System of Logic, A | ||
Milton, John:Paradise Lost | ||
Johnson, Samuel:Lives of the Poets | ||
Shakespeare, William:Julius Caesar | ||
Mill, John Stuart:On Liberty | ||
Bunyan, John:Saved by Grace | ||
This is somewhat untidy, as they are in no particular order. But we can use the sort command to straighten that out: | Это немного неопрятно, т.к. они идут не по порядку. Но вы можете использовать команду sort для упорядочивания списка: | |
$ sort books | ||
Bartlett, John:Familiar Quotations | ||
Bunyan, John:Pilgrim's Progress, The | ||
Bunyan, John:Saved by Grace | ||
Carroll, Lewis:Through the Looking-Glass | ||
Defoe, Daniel:Robinson Crusoe | ||
Johnson, Samuel:Lives of the Poets | ||
London, Jack:John Barleycorn | ||
Mill, John Stuart:On Liberty | ||
Mill, John Stuart:On Nature | ||
Mill, John Stuart:System of Logic, A | ||
Milton, John:Paradise Lost | ||
Shakespeare, William:Hamlet | ||
Shakespeare, William:Julius Caesar | ||
Ah, now you have a list nicely sorted by author. How about getting a list just of authors, without titles? You can do that with the cut command: | Теперь у Вас есть список, отстортированый по автору. Как насчет того, чтобы получить список только с авторами, без заголовков? Вы можете это сделать с помощью команды cut: | |
$ cut -d: -f1 books | ||
Carroll, Lewis | ||
Shakespeare, William | ||
Bartlett, John | ||
Mill, John Stuart | ||
London, Jack | ||
Bunyan, John | ||
Defoe, Daniel | ||
Mill, John Stuart | ||
Milton, John | ||
Johnson, Samuel | ||
Shakespeare, William | ||
Mill, John Stuart | ||
Bunyan, John | ||
A little explanation here. The -d option chose a colon as the delimiter (separator). This tells cut to break up each line wherever a delimiter appears, and each separate part of the line is called a field. In our format, the author's name appears as the first field, so we have put a 1 with the -f option to tell cut that we want to see just that field. |
