0% found this document useful (0 votes)
2 views4 pages

OS102 Individual Activity 3

The document outlines an activity for students to explore various `grep` command options for text searching on a Linux system. It includes instructions for creating files, executing specific `grep` commands, and understanding advanced options for filtering and counting matches. Students are required to document their commands and outputs with screenshots for submission by March 11, 2025.

Uploaded by

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

OS102 Individual Activity 3

The document outlines an activity for students to explore various `grep` command options for text searching on a Linux system. It includes instructions for creating files, executing specific `grep` commands, and understanding advanced options for filtering and counting matches. Students are required to document their commands and outputs with screenshots for submission by March 11, 2025.

Uploaded by

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

Activity: Exploring All Possible `grep` Commands

Week 4 Topic: File and Text Management

Objective:

By the end of this activity, students should be able to:

- Use various `grep` command options for text searching.

- Understand how to refine searches using `grep` options.

Instructions:

Perform the following tasks on a Linux system and provide screenshots of your commands and
outputs.

Part 1: Basic `grep` Usage

1. Create a file named `data.txt` with the following content:

```

Linux is an open-source operating system.

The grep command is used for searching text in files.

Learning Linux commands can be very useful.

File searching can be done efficiently with grep.

GREP is case-sensitive by default.

```

2. Use `grep` to search for the word Linux in `data.txt`.

- Command: `grep "Linux" data.txt`


3. Search for the word grep in `data.txt` and display the matching line.

- Command: `grep "grep" data.txt`

Part 2: Case-Insensitive and Exact Match Searching

4. Search for linux (lowercase) using a case-insensitive option.

- Command: `grep -i "linux" data.txt`

5. Search for lines that contain only the exact word grep, not as part of another word.

- Command: `grep -w "grep" data.txt`

Part 3: Filtering and Counting Matches

6. Display all lines that do not contain the word Linux.

- Command: `grep -v "Linux" data.txt`

7. Count the number of lines that contain the word grep.

- Command: `grep -c "grep" data.txt`

Part 4: Advanced `grep` Options

8. Display line numbers where grep appears.

- Command: `grep -n "grep" data.txt`


9. Highlight matches using color.

- Command: `grep --color=auto "grep" data.txt`

10. Search for multiple words (`Linux` and `grep`) at once.

- Command: `grep -E "Linux|grep" data.txt`

11. Show only the matched word instead of the entire line.

- Command: `grep -o "grep" data.txt`

Part 5: Searching in Multiple Files

12. Create another file named `info.txt` and add:

```

Linux is widely used in servers.

grep is a powerful text search tool.

Many developers prefer using Linux.

```

13. Search for Linux in both `data.txt` and `info.txt`.

- Command: `grep "Linux" data.txt info.txt`


Part 6: Searching Recursively in Directories

14. Search for Linux in all `.txt` files in the current directory.

- Command: `grep -r "Linux" *.txt`

15. Search for Linux in all files, even hidden ones.

- Command: `grep -r --hidden "Linux" ~/`

Submission Guidelines:

- Submit a document (PDF or Word) containing the commands and outputs.

- Include screenshots for verification.

Deadline: March 11, 2025

You might also like