We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
uniq's output format doesn't match that required by the guidelines ("There shouldn't be leading or trailing spaces. Please note that the uniq -c command by itself will generate the output in a different format.").
https://ss64.com/bash/sed.html
sed "is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline)."
The relevant section is "s/REGEXP/REPLACEMENT/FLAGS". This uses regex (so you would need to review that, if you are not familiar - it's basically a way to match patterns in text). The "^" is the anchor for the beginning of the line. The "[ \t]" is a character class containing both a space and a tab. The "*" means to match the character class 0 or more times.
Since the REPLACEMENT section is blank (//), that means to match either a space or a tab as many times as it occurs at the beginning of the line and replace it with nothing. Essentially, this just removes the blank space at the beginning of the line, formatting it as directed.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
'Uniq' command #3
You are viewing a single comment's thread. Return to all comments →
uniq's output format doesn't match that required by the guidelines ("There shouldn't be leading or trailing spaces. Please note that the uniq -c command by itself will generate the output in a different format.").
https://ss64.com/bash/sed.html sed "is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline)."
The relevant section is "s/REGEXP/REPLACEMENT/FLAGS". This uses regex (so you would need to review that, if you are not familiar - it's basically a way to match patterns in text). The "^" is the anchor for the beginning of the line. The
"[ \t]"
is a character class containing both a space and a tab. The"*"
means to match the character class 0 or more times.Since the REPLACEMENT section is blank (//), that means to match either a space or a tab as many times as it occurs at the beginning of the line and replace it with nothing. Essentially, this just removes the blank space at the beginning of the line, formatting it as directed.