Question

In: Computer Science

Ubuntu Linux HW5: text processing; scripting 1. Write a Linux command to rewrite the /var/passwd file...

Ubuntu Linux

HW5: text processing; scripting

1. Write a Linux command to rewrite the /var/passwd file to have a tab for each delimiter ':'. Hint: use tr

2. Write a Linux command to extract the user names and sort them. Hint: use cut

3. Write a for loop to to display a time table, e.g., 17 x 1 = 17; 17 x 2 = 34; etc., as follows:

17 x 1 = 17 17 x 2 = 34

17 x 3 = 51 17 x 4 = 68

17 x 5 = 85 17 x 6 = 102

17 x 7 = 119 17 x 8 = 136

17 x 9 = 153 17 x 10 = 170

17 x 11 = 187 17 x 12 = 204

17 x 13 = 221 17 x 14 = 238

17 x 15 = 255 17 x 16 = 272

17 x 17 = 289 4.

Write a Linux command to download the following webpage to the fail called "viral-diseases" Hint: use wget

5. Using a regular expression, write a Linux command to extract URL addresses from the viral-diseases. The URL starts with "www" and ending with "com" or "gov". Hint: use grep -E 6. Write a bash shell to

1) using a for loop to create the directory called "jyoon_0" to "jyoon_9";

2) change directory to each of the directories created,

3) write the sentence "Yoon visited in directory jyoon_0t" in the file jyoon_0.txt",

4) attach the timestamp to the file;

5) writhe the same sentence to the standard output device,

6) the timestamp too;

7) do this to all those 10 directories, and

8) at the end, write "All done" to the standard output device. So, the example standard output:

jyoon@MT-UBUN01:~$ ./hw5create.sh

Yoon visited jyoon_0 directory

Thu 09 Jul 2020 11:48:42 AM EDT

Yoon visited jyoon_1 directory

Thu 09 Jul 2020 11:48:42 AM EDT

Yoon visited jyoon_2 directory

Thu 09 Jul 2020 11:48:42 AM EDT

Yoon visited jyoon_3 directory

Thu 09 Jul 2020 11:48:42 AM EDT

Yoon visited jyoon_4 directory

Thu 09 Jul 2020 11:48:42 AM EDT

Yoon visited jyoon_5 directory

Thu 09 Jul 2020 11:48:42 AM EDT

Yoon visited jyoon_6 directory

Thu 09 Jul 2020 11:48:42 AM EDT

Yoon visited jyoon_7 directory

Thu 09 Jul 2020 11:48:42 AM EDT

Yoon visited jyoon_8 directory

Thu 09 Jul 2020 11:48:42 AM EDT

Yoon visited jyoon_9 directory

Thu 09 Jul 2020 11:48:42 AM EDT

All Created!

One of the directories has the following:

jyoon@MT-UBUN01:~$ cd jyoon_5

jyoon@MT-UBUN01:~/jyoon_5$ ls

jyoon_5.txt jyoon@MT-UBUN01:~/jyoon_5$ cat jyoon_5.txt

Yoon visited jyoon_5 directory

Thu 09 Jul 2020 11:48:42 AM EDT

jyoon@MT-UBUN01:~/jyoon_5$

Note that the directory name, file name and your name should be formed with your login ID, but not jyoon, which is not yours!

Solutions

Expert Solution

Solution:

1.

the tr command in linux is used to replace the characters present in the standard input with the given characters.

Since tr can only operate on standard input we need to pass our data to the standard input then pipe it to the tr command.

So, we use cat command to view the contents of the file and then pipe the data to the tr command then redirect the output to a temporary file ( /var/passwdt ) and then rename the temporary file with original file name.( /var/passwd in this case )

Command looks like:

cat /var/passwd | tr -s ':' '\t' > /var/passwdt
mv /var/passwdt /var/passwd 

Output:

/var/passwd file before rewriting

/var/passwd file after rewriting

2.

the cut command separates or cuts the given file data based on the given condition. In the above question we replaced all the : 's with "\t" characters now using cut we can extract the field values. field 1 contains the usernames. To sort the usernames we use sort command.

Command to sort the usernames:

cut -f 1 /var/passwd | sort

Output:

3.

The for loop looks something like shown below. when you are using * in expr you need to use it as \* because bash treats * as special character..

LOOP:

for((i=1;i<=17;i++))
{
        echo "17 x $i = "$(expr 17 \* $i)       
}

OUTPUT:

I hope this would help...................:-))


Related Solutions

Ubuntu Linux HW2: 1. Give one line of the Linux command to see your (your login...
Ubuntu Linux HW2: 1. Give one line of the Linux command to see your (your login ID) credential data from the passwd file. Use a pipe and grep command. 2. Give one line of the Linux command to calculate the following and save it in the hex to a file calcOut. Use bc and <<<. 3+2*4 Submit Screenshots HW3: Permission Show the result clearly after each of the following commands are executed. 1. Create a subdirectory, “HW3”. Write the Linux...
In Linux (Ubuntu), write a script to check command arguments (3 arguments maximum). Display the argument...
In Linux (Ubuntu), write a script to check command arguments (3 arguments maximum). Display the argument one by one. If there is no argument provided, remind users about the mistake. If there is an easy way to use a loop to get all arguments, use it? a. Display the source code in an editor (#4-1) b. Execute your script in the terminal, and display the command and the result (#4-2)
For Linux: Write a command to append the top 20 lines of the file seq.fasta to...
For Linux: Write a command to append the top 20 lines of the file seq.fasta to a second file named combined.seq.
Linux Ubuntu 1. Use the appropriate commands to locate the device file used by the device,...
Linux Ubuntu 1. Use the appropriate commands to locate the device file used by the device, mount the filesystem to a directory of your choice, and check the filesystem for errors. 2. Finally, add a line to /etc/fstab to ensure that the filesystem can be easily mounted in the future (this line should not automount the filesystem at boot time). You have to document all your steps and provide the screenshot of your work process.
(Complete Using Ubuntu) Please try each command in Linux system, and get screenshots (you may put...
(Complete Using Ubuntu) Please try each command in Linux system, and get screenshots (you may put multiple commands in one screenshot) which can show how actually each command runs. Also, give a brief description (one or two sentences) for each command. For the commands which have multiple switches/parameters, please try one popular switch/parameter. Linux Commands: rm,cp ,mv (name), ld, ftp, more, less, cat (date), tar, top, ps (name), kill, df, last, patch, mkdir (date)
In linux , Using a simple text editor, create a text file with the following name...
In linux , Using a simple text editor, create a text file with the following name &quot;Test&quot; and content: GNU GENERAL PUBLIC LICENSE The GNU General Public License is a free, copy left license for the GNU General Public License is intended to guarantee your freedom to GNU General Public License for most of our software; it applies … 2-Write the command to create the text file. 3-Print the file permissions. 4-Create a directory named &quot;361&quot; 5-Copy file &quot;Test&quot; to...
Linux Directories, File Properties, and the File System in C Code your version of mv command...
Linux Directories, File Properties, and the File System in C Code your version of mv command in C The mv command is more than just a wrapper around the rename system call. Write a version of mv that accepts two argument. The first argument must be the name of a file, and the second argument may be the name of a file or the name of a directory. If the destination is the name of a directory, then mv moves...
Linux Directories, File Properties, and the File System in C Your version of find command Try...
Linux Directories, File Properties, and the File System in C Your version of find command Try running the find command in the shell and observe the output. Try it in different folders to make sure you understand what it prints out. $ find Write your version of the find command and add comments.
DISCUSS COMPARING TEXT EDITORS IN LINUX. Research the different text editors available in Linux and write...
DISCUSS COMPARING TEXT EDITORS IN LINUX. Research the different text editors available in Linux and write up a comparison of each. Your comparison should include a recommendation as to the editor you feel would be most useful and why.
this is bash scripting. a. Explain the difference between grep and egrep? b. Write a command...
this is bash scripting. a. Explain the difference between grep and egrep? b. Write a command to list files where third letter is x or y? c. Write command to remove array element with id 5
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT