Question

What command would you give to print (display on the screen) the contents of commented.cpp with...

  1. What command would you give to print (display on the screen) the contents of commented.cpp with all inline comments removed (and no other changes to the text)? I need to do this with the sed command, and as you know all inline comments in cpp start with "//".

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution :

commented.cpp

#include <iostream>
using namespace std;
//Firt line
int main()
{
//Second line
cout<<"HelloWorld"<<endl;
//Third line
return 0;
}
//Last line

OUTPUT:

Add a comment
Answer #2

To remove all inline comments starting with "//" from the file "commented.cpp" using the sed command, you can use the following command:

bashCopy codesed 's/\/\/.*//' commented.cpp

Explanation:

  • sed: The command for stream editor.

  • s: The substitute command in sed to perform search and replace.

  • \/\/: The pattern to search for. Since "/" is a special character in sed, we need to escape it with "" to match "//" literally.

  • .*: The pattern to match any characters after "//" until the end of the line.

  • //.*//: The replacement pattern is empty, which means we are effectively removing the inline comments.

Running this command will display the contents of "commented.cpp" with all inline comments removed on the screen. Note that this command only displays the modified output on the screen and does not change the original file. If you want to save the modified content to a new file, you can use the -i flag with sed:

bashCopy codesed -i 's/\/\/.*//' commented.cpp

This will perform the same inline comment removal directly in the "commented.cpp" file. Make sure to create a backup of the file before using the -i flag to avoid accidental data loss.


answered by: Hydra Master
Add a comment
Know the answer?
Add Answer to:
What command would you give to print (display on the screen) the contents of commented.cpp with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • INTRO TO UNIX COURSE Comments in C++ come in two forms: the block format started by...

    INTRO TO UNIX COURSE Comments in C++ come in two forms: the block format started by a /* and ending with a */, often on different lines, and the inline format started by // and ended at the end of the line. What command would you give to list all lines of commented.cpp that contain inline comments? What command would you give to print (display on the screen) the contents of commented.cpp with all inline comments removed (and no other...

  • a) How would you use the ls command to display all of the files/directories in the...

    a) How would you use the ls command to display all of the files/directories in the directory ‘/sbin’ that start with ‘bl’? b) How would you use the ls command to display all of the files/directories in your current directory that contain the word ‘grade’ somewhere in the name and end with ‘.pdf’? c) How would you use the ls command to display all of the files/directories in your current directory that are any two characters followed by the file...

  • For each command give me the ENTIRE COMMAND SEQUENCE. If I ask you 'What command would...

    For each command give me the ENTIRE COMMAND SEQUENCE. If I ask you 'What command would I use to move the file one.txt to the parent directory and rename it to two.txt?", the answer is NOT 'mv'. That is only part of the command. 16. What command could I run to determine whether the ssh daemon is listening? With OpenSSH installed and running, the result should show that ssh/port 22 as "listening.' (5 pts) 17. Create a crontab entry that...

  • QUESTION 1 What will be the output of following Unix command: find / -name ‘*’ A....

    QUESTION 1 What will be the output of following Unix command: find / -name ‘*’ A. List all files and directories recursively starting from / B. List a file names * in / C. List all files in / directory D. List all files and directories in / directory QUESTION 2 Which command is used to extract a column/field from a text file / input. A. paste B. get C. cut D. tar QUESTION 3 Which command creates an empty...

  • This is done in Linux terminal. Modify the .bashrc file using command line which would add...

    This is done in Linux terminal. Modify the .bashrc file using command line which would add the following functionality to your shell upon opening a new terminal: 1. Alias called “fc” (short for “folder contents) invoking the command “ls -lah”B. Welcome message “This is demo number 7” C. Variable “semester” being equal to “Winter 2020” and print the value on screen 2. Create any directory of your choice and add it to PATH variable. 3. Show an example of local...

  • LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check...

    LINUX QUESTIONS (dont have to display output, I will be running these commands myself to check the output) Display the command(s) used to do the following: create an empty file called history by using just a redirection operator. Verify and show. Show/verify all results (i.e., all commands and their corresponding outputs). Wait 1 minute or more and then display the command(s) used to do the following: change the timestamp on the history file you just created. Verify/display the change. Show/verify...

  • please write down the code Thank you. Write a simple shell that is similar to this: while(1 //repeat forever //display prompt on screen type_prompt )i read_command ( command, parameters); // read inp...

    please write down the code Thank you. Write a simple shell that is similar to this: while(1 //repeat forever //display prompt on screen type_prompt )i read_command ( command, parameters); // read input from terminal if ( fork) 0) // parent //wait for child wait NULL elset execve (commamd, parameters, 0 // execute command but contains enough code that it actually works so you can test it. For simplicity, you may assume that all commands are in the directory /bin Write...

  • do numbers 4-8 4. Given any directory, use the Is command to display: • all files...

    do numbers 4-8 4. Given any directory, use the Is command to display: • all files and sub-directories starting with the letter "D" (note do not list anything in any sub-directory) • its immediate sub-directories (sub-directories only, and no other ordinary files) its immediate hidden sub-directories only - take a screenshot (#3-3) that clearly shows the command and the result. 5. Assume that the following files are in the working directory: $ ls intro notesb ref2 section 1 section3 section4b...

  • Using system calls you have learned so far, build your own command called fpart to display...

    Using system calls you have learned so far, build your own command called fpart to display (or echo) a portion of any text file. Please follow the following requirements 1. Your command must be typed in these styles a. Şfpart filename.txt start byte end _byte b. Şfpart filename.txt start_byte 2. If the input file (filename.txt) is a non-text file, then a message must be displayed like this: Input file is not a text file 3. Here is an example run....

  • What unix / linux command would I use to execute this: Display only the fifth field...

    What unix / linux command would I use to execute this: Display only the fifth field on each line in the file myclass using a delimiter of :

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT