Multiple choice technology programming languages

To delete the last word of each line in the file test1

  1. sed 's/ */$//' test1
  2. sed 's/ *$//' test1
  3. sed 's/ \*$//' test1
  4. sed 's/ \*$\/\/' test1
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The sed command 's/ *$//' removes trailing spaces from each line - it matches zero or more spaces at the end of the line and replaces them with nothing. The $ anchor matches the end of line, and * matches zero or more spaces. This effectively strips trailing whitespace.