0% found this document useful (0 votes)
1 views1 page

1

The document provides a series of grep commands for extracting specific lines and words from a text file named 'poem.txt'. It includes commands for identifying blank lines, lines containing certain words, patterns with specific letters, and lines with particular formatting. Each command is accompanied by a brief description of its function.

Uploaded by

tulasipalagiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

1

The document provides a series of grep commands for extracting specific lines and words from a text file named 'poem.txt'. It includes commands for identifying blank lines, lines containing certain words, patterns with specific letters, and lines with particular formatting. Each command is accompanied by a brief description of its function.

Uploaded by

tulasipalagiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

To pick out the blank lines in the file: (find lines that start and end with nothing in between.

Cmd: grep '^$' poem.txt

2. To pick out lines with rep, word, or more. (use the alternator |)

Cmd: grep -E 'rep|word|more' poem.txt

3. To pick out lines that have at least two p's followed by any number of letters followed by
'ore'. The p's do not have to be next to each other. ( .* dot and then asterisk will find any
characters in the search text)

Cmd: grep -E 'p.*p.*ore' poem.txt

4. To pick out all the lines with v, z or I in them: use the class brackets [ ] to solve this one

Cmd: grep '[vzI]' poem.txt


5. To pick out all the lines that do not start with an uppercase letter.

Cmd: grep -v '^[A-Z]' poem.txt

6. To pick out all the lines that end with a dash –

Cmd: grep '-$' poem.txt

7. To pick out all the words that end with ore

Cmd: grep -o '\b[a-zA-Z]*ore\b' poem.txt

8. To pick out all the words that start with f or F

Cmd: grep -o '\b[Ff][a-zA-Z]*\b' poem.txt

9. To pick out lines that uses first letter alliteration - starting two words with the same letter.
( .* dot and then asterisk will find any characters in the search text)

Cmd: grep -E '^\b(\w)\w*\s+\1\w*\b' poem.txt

You might also like