Menu

UNIX TUTORIALS - Unix - Pipes & Filters

Unix - Pipes & Filters

ADVERTISEMENTS

The grep Command:

OptionDescription
-vPrint all lines that do not match pattern.
-nPrint the matched line and its line number.
-lPrint only the names of files with matching lines (letter "l")
-cPrint only the count of matching lines.
-iMatch either upper- or lowercase.

ADVERTISEMENTS

The sort Command:

OptionDescription
-nSort numerically (example: 10 will sort after 2), ignore blanks and tabs.
-rReverse the order of sort.
-fSort upper- and lowercase together.
+xIgnore first x fields when sorting.

ADVERTISEMENTS

The grep Command:

$grep pattern file(s)

$ls -l | grep "Aug"
-rw-rw-rw-   1 john  doc     11008 Aug  6 14:10 ch02
-rw-rw-rw-   1 john  doc      8515 Aug  6 15:30 ch07
-rw-rw-r--   1 john  doc      2488 Aug 15 10:51 intro
-rw-rw-r--   1 carol doc      1605 Aug 23 07:35 macros
$

$ls -l | grep -i "carol.*aug"
-rw-rw-r--   1 carol doc      1605 Aug 23 07:35 macros
$

The sort Command:

$sort food
Afghani Cuisine
Bangkok Wok
Big Apple Deli
Isle of Java
Mandalay
Sushi and Sashimi
Sweet Tooth
Tio Pepe's Peppers
$

$ls -l | grep "Aug" | sort +4n
-rw-rw-r--  1 carol doc      1605 Aug 23 07:35 macros
-rw-rw-r--  1 john  doc      2488 Aug 15 10:51 intro
-rw-rw-rw-  1 john  doc      8515 Aug  6 15:30 ch07
-rw-rw-rw-  1 john  doc     11008 Aug  6 14:10 ch02
$

The pg and more Commands:

$ls -l | grep "Aug" | sort +4n | more
-rw-rw-r--  1 carol doc      1605 Aug 23 07:35 macros
-rw-rw-r--  1 john  doc      2488 Aug 15 10:51 intro
-rw-rw-rw-  1 john  doc      8515 Aug  6 15:30 ch07
-rw-rw-r--  1 john  doc     14827 Aug  9 12:40 ch03
	.
	.
	.
-rw-rw-rw-  1 john  doc     16867 Aug  6 15:56 ch05
--More--(74%)