LABORATORY-1A
Shell Commands
grep-commands
grep = global regular expression print
The grep filter searches a file for a particular pattern of characters and displays all the line that contain that pattern.
Syntax: grep [options] pattern [files]
Options:
-c: This print only a count of the lines that match a pattern
-h:Display the matched lines,but do not display the file names
-i: Ignores, case for matching
-l: Display the list of a filenames only
-n: Display the matched lines and their line numbers.
-v: This prints out all the lines that do not matches the pattern.
-e exp: Specifies expression with this option. {Can use multiple times}
-f file: Takes pattern from file, one per line.
-E: Trest pattern as an extended regular expression
-w: Match whole word
-o: Print only the matched parts of a matching line.
-A n: Print searched line and n lines after the result
-B n: Print searched line and n lines before the result
-C n: Print searched line and n lines after before the result
^: Starts with
$: Ends with
[]: Containing at least one character from given set
[:upper:]: Matches all the upper case letter.
[:lower:]: Matches all the lower case letter.
head -[n]: Displays the specified number of lines from the top.
tail -[n]: Displays the specified number of lines from the bottom.
cut: Displays bytes, characters or fields from the lines of a file.
eg:- cut -b [3,6,9] filename : display 3,6,9 bytes of each line
cut -d " " -f [n] filename: space as a delimeter and display the nth field.