~/ learn/ comp-325/ cards/ Every line is a row of fields
1 of 11

Print one column, then select rows before printing it

Print one column, then select rows before printing it

Answer

ps -ef | awk '{print $2}' ps -ef | awk '/sleep/ {print $2}' ps -ef | awk '/sleep/ {print 1, 2}'

Line 1 has an action and no pattern, so it runs on every record. Lines 2 and 3 add a regular-expression pattern matched against the whole record. The comma between two field references inserts a space; drop it and the values are concatenated.

POSIX.1-2024 (IEEE Std 1003.1-2024) Shell and Utilities: awk. The textbook names awk as a regex tool and never teaches it.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/b5e360a1-18ef-4404-821a-fc70fd14a644/flashcard utf-8 LF