3.3.2. Filtering Vertically¶
See also
- Video about Filtering Data Vertically with Cut and Awk
3.3.2.1. cut¶
-
cut
Print selected parts of lines from each FILE to standard output. cut can also read data from stdin (usually via a pipe).
- SYNOPSIS
- cut [OPTION]… [FILE]…
-
-d
,
--delimiter
=DELIM
¶ Use DELIM instead of TAB for field delimiter
-
-f
,
--fields
=LIST
¶ Select only these fields; also print any line that contains no delimiter character, unless the -s option is specified
3.3.2.2. awk¶
3.3.2.3. paste¶
-
paste
Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, to standard output. With no FILE, or when FILE is -, read standard input.
The paste command is sort of the opposite of cut. The cut command filters vertical data (columns) from the data and paste takes columns of data from separate files and put them together.
SYNOPSIS
paste [OPTION]… [FILE]…
-
-d
,
--delimiters
=LIST
¶ reuse characters from LIST instead of TABs
-
-s
,
--serial
¶
paste one file at a time instead of in parallel
Files contain the desired columns and paste merges the columns.
$ getent passwd | tail -5 | cut -d: -f3 > field3
$ getent passwd | tail -5 | cut -d: -f7 > field7
$ paste -d: field3 field7
558:/bin/bash
559:/bin/bash
560:/bin/bash
561:/bin/bash
562:/bin/bash