In: Computer Science
PLEASE ANSWER ALL OF THEM.
Use the following file listing called intro.txt to answer the questions.
Make sure to use regular expressions. Number your answers 1 through 7.
The Unix operating system was pioneered by Ken Thompson and Dennis Ritchie at Bell Laboratories in the late 1960s. One of the primary goals in the design of the Unix system was to create an environment that promoted efficient program development.
1-Write the grep command to output all lines that begin with an uppercase T.
2-Write the grep command to output all lines that end with a lowercase n.
3-Write the grep command to match and output all lines that have a lowercase p followed by any single character followed by a lowercase o.
4-Write the grep command to match and output all words that contain digits.
5-Write the grep command to match and output a sequence of alphabetic letters that is exactly 9 characters long.
6-Write a command using tr to remove all spaces (all the space characters) from intro.txt
7-Write a command using sed to remove all spaces (all the space characters) from intro.txt
#1-Write the grep command to output all lines that begin with an uppercase T.
> grep "^T" intro.txt
# '^' means start of string
#2-Write the grep command to output all lines that end with a lowercase n.
> grep "n$" intro.txt
# '$' means end of string
#3-Write the grep command to match and output all lines that have a lowercase p followed by any single character followed by a lowercase o.
> grep "p.o" intro.txt
#Here, '.' represents a single character
#4-Write the grep command to match and output all words that contain digits.
> grep -Po "\w*\d+\w*" intro.txt
#Here, "-P" stands for Perl regular expresions and -o gives output matched lines; "\d" is for digits in between any words \w*
#5-Write the grep command to match and output a sequence of alphabetic letters that is exactly 9 characters long.
> grep -Po "[a-zA-Z]{9}" intro.txt
#any case strings(a-z or A-Z) contain exactly 9 characters
#6-Write a command using tr to remove all spaces (all the space characters) from intro.txt
> tr -d ' ' < intro.txt
# 'tr -d' translate or delete characters here spaces deleted (' ')
#7-Write a command using sed to remove all spaces (all the space characters) from intro.txt
> sed 's/\s//g' intro.txt
# sed- stream editor, '\s' white space chacracters instead of space( ' ' ) and g is a global allow to delete both in between numbers and strings