Answered step by step
Verified Expert Solution
Question
1 Approved Answer
og files, and other text - based data in a Linux environment. Please provide a screenshot as proof of work for every instruction executed. Log
og files, and
other text
based data in a Linux environment.
Please provide a screenshot as proof of work for every instruction executed.
Log in to Ubuntu
instructions:
Create a text file:
Create a text file
e
g
sampletxt
using a text editor or command line tools such as touch and
echo. Add some random text to this file.
You can use the text editor and save the file with the
txt extension.
Note: Please choose a sample text such that the below commands can be effectively executed
View the file contents:
Use the cat command to view the contents of the text file you created.
Review of the text:
Use the grep command to search for a specific word or phrase in a text file. For example, look
for occurrences of the word "Linux."
grep
i
text
to
search
sampletxt
Read the alphabet:
Use the wc command to count the number of words and characters in a text file.
Complete the text:
Use the sort command to sort the text in a file alphabetically.
Create a new file with the following text:
Use the
or
operator to redirect the sorted output to another file
e
g
sorted
sample.txt
Replace text:
Use the sed command to replace a specific word or phrase in the root text file
e
g
Ubuntu
instead of "Linux"
Add text to the original file:
Use the
operator to add additional information to the original file
e
g
add a few lines
Extract specific Lines:
Use the head and tail commands to remove the first and last lines of the text file.
Remove specific Lines:
Use the sed or grep
v command to extract specific lines containing a specific word from a text
file.
PART B
NOTE:
YOU FIRST HAVE TO CREATE FILES IN A DIRECTORY AND SHOW
SCREENSHOT OF CREATED FILE NAMES
YOU CAN CREATE FEW DUMMY.TXT FILES
PRODUCE A SCREENSHOT WHEN YOU ARE RUNNING THE SCRIPT IN THE
TERMINAL
PRODUCE A SCREENSHOT CONSISTING OF RENAMED FILES
Goal: Write a simple shell script to automate a common task.
Steps:
Create a Shell Script:
Create a text file with a
sh extension. You can use a text editor of your choice. For example,
you can use the nano text editor to create a new script file named rename
files.sh:
bash
Copy code
nano rename
files.sh
Write the Script:
Inside the rename
files.sh script, you can write a script that renames all
txt files in a directory
by adding a prefix to their filenames.
Make the Script Executable:
Before you can run the script, you need to make it executable. You can do this with the chmod
command:
bash
Copy code
chmod
x rename
files.sh
Run the Script:
You can now run the script by providing a prefix as an argument. Remember to replace new
with the prefix you want to use.
This assignment not only automates a visible task but also helps you learn the basics of
scripting, conditional statements, and loops in Bash
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started