100 Useful Command-Line Utilities

by Oliver; 2014

75. read

read is a shell builtin that I like to use in loops. You can read up a file with a while loop using read—e.g., spit out file.txt exactly as is:
$ while read x; do echo "$x"; done < file.txt
Another example:
$ echo -e '1\t2\n3\t4\n5\t6'
1       2
3       4
5       6
$ echo -e '1\t2\n3\t4\n5\t6' | while read x y; do echo $x; done
1
3
5

<PREV   NEXT>