Name
getline
Synopsis
getline getline [var] [<file]command| getline [var]command|& getline [var] {G}
Read next line of input.
The second form reads input from file, and the third form reads the output of command. All forms read one record at a time, and each time the statement is executed, it gets the next record of input. The record is assigned to $0 and is parsed into fields, setting NF, NR and FNR. If var is specified, the result is assigned to var and $0 and NF are not changed. Thus, if the result is assigned to a variable, the current record does not change. getline is actually a function, and it returns 1 if it reads a record successfully, 0 if end-of-file is encountered, and −1 if for some reason it is otherwise unsuccessful.
The fourth form reads the output from coprocess command. See the section Coprocesses and Sockets in Coprocesses and Sockets for more information.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access