Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone do it asap The first thing we want to do is change the file type of ordinary files in your file listing (as

image text in transcribed

image text in transcribed

image text in transcribed

can someone do it asap

The first thing we want to do is change the file type of ordinary files in your file listing (as shown through the first character in the file permissions) from - to "R". we can do this very easily using regex with the following command $ sed -i "s/A-/R/g" sedfile.txt This does an in-place substitution to your sedfile.txt file for all lines that start with "- directed by the regex metacharacter "A". Now rather than printing out the entire file (which could be very long) to show the resulting changes, let's just print out the first 10 lines of the file using sed. We do this with the following command sed -n 1,10p sedfile.txt The "-n" is needed to only print out the first 10 lines as the default is to print out every line You may have noticed that the first line of your sedfile.txt file starts with the word "total" followed by a number and does not follow the listing format shown in the above figure. To just show the actual first 10 files of this listing, we can easily modify the previous command by using "2,11p" instead. But suppose we just want to delete this first line instead? We can do this with the following command $ sed -i ld sedfile.txt This line simply deletes in-place the first line of your sedfile.txt file Now, we want to be able to add a new line of text to your file after a pattern match is found. Look at the fifth line of your file and find a unique pattern specific to this line only. It may be something like the date, size in bytes, or the file name. To add this new line after this fifth line in your file, issue the following command $ sed-i '/YOUR PATTERN/a This is a new line' sedfile. txt Instead of "YOUR PATTERN", you would enter the unique pattern specific to the fifth line of your file. Print out the first 10 lines of your sedfile.txt file again to verify that these changes (deleting the first line and adding a new line) worked sed -n 1,10p sedfile.txt We're finished with sed now. sed is a powerful stream editor. There are many more things that you can do with sed, but for now let's change our focus to gawk! Do NOT type exit yet as we will continue and include the work on gawk as well in this file The gawk Programming Language This time, we're going to focus on process instead of files. Now, create a list of running processes on your system by issuing the following command from your command prompt as follows $ ps -ef > gawkfile.txt The first thing we want to do is change the file type of ordinary files in your file listing (as shown through the first character in the file permissions) from - to "R". we can do this very easily using regex with the following command $ sed -i "s/A-/R/g" sedfile.txt This does an in-place substitution to your sedfile.txt file for all lines that start with "- directed by the regex metacharacter "A". Now rather than printing out the entire file (which could be very long) to show the resulting changes, let's just print out the first 10 lines of the file using sed. We do this with the following command sed -n 1,10p sedfile.txt The "-n" is needed to only print out the first 10 lines as the default is to print out every line You may have noticed that the first line of your sedfile.txt file starts with the word "total" followed by a number and does not follow the listing format shown in the above figure. To just show the actual first 10 files of this listing, we can easily modify the previous command by using "2,11p" instead. But suppose we just want to delete this first line instead? We can do this with the following command $ sed -i ld sedfile.txt This line simply deletes in-place the first line of your sedfile.txt file Now, we want to be able to add a new line of text to your file after a pattern match is found. Look at the fifth line of your file and find a unique pattern specific to this line only. It may be something like the date, size in bytes, or the file name. To add this new line after this fifth line in your file, issue the following command $ sed-i '/YOUR PATTERN/a This is a new line' sedfile. txt Instead of "YOUR PATTERN", you would enter the unique pattern specific to the fifth line of your file. Print out the first 10 lines of your sedfile.txt file again to verify that these changes (deleting the first line and adding a new line) worked sed -n 1,10p sedfile.txt We're finished with sed now. sed is a powerful stream editor. There are many more things that you can do with sed, but for now let's change our focus to gawk! Do NOT type exit yet as we will continue and include the work on gawk as well in this file The gawk Programming Language This time, we're going to focus on process instead of files. Now, create a list of running processes on your system by issuing the following command from your command prompt as follows $ ps -ef > gawkfile.txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started