Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need commands in linux that can do the following. a) Find if the file random c

ID: 3587874 • Letter: I

Question

I need commands in linux that can do the following.

a) Find if the file random contains the word "homer". The expression should find a case-insensitive match

b) Find empty lines (no space) in a file. The character ^ denotes the beginning of the line and $ denotes its ending

c) Count number of empty lines (no space) in a file

d) To find all the lines that have letters

e) Find all the lines that ONLY have letters

f) Find all the lines that ONLY have letters and numbers

g) Find all lines that does not have numbers

h) Find lines that have contents between a pair of square brackets

Explanation / Answer

Commands:

a) in linux, the most popular command to search for a pattern(string or word) in a file is grep.

Below is the command to find the word "homer" in a file random

$ grep -i "homer" random.txt

Ignores upper and lower case distinction.

All lines containing the word unix, regardless of if it's lowercase, uppercase or a mix of both, are returned.

b)grep "^s*$" filename

c)Count number of empty lines(no space)in a file:

-P 'S' will match any line contains non-space

-v select non-matching lines

-c print a count of matching lines

d)To find all the lines that have letters

Command is: grep '[a-zA-Z]'

or we can use egrep -v [a-zA-Z] filename

e)grep '[a-zA-Z] 'find all the lines that only have letters

f)grep '[a-zA-Z0-9]' find all the lines that only have letters and numbers

g)If your grep has the -L (or --files-without-match) option:

then it finds all the lines that does not have numbers

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote