Sort 46 Discussions, By:
Please Login in order to post a comment
uniq -ic|cut -c7-
Can you please help me in understanding what exactly thie flag -i in uniq does?
-i is for ignoring the case and c is for number of times the lines are repeated.
Could u get why 7 is used???
The question requires you to remove the space from the output you see at the start, so the cut -c7- will display from character 7 to the end (because there is 6 spaces).
How you counted that output is 6 spaces away...?
uniq -ci | sed 's/^[ \t]*//'
Plz make me understand. I am unable to get the logic after pipe.
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.").
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.
Thanks a lot for interpreting the commands.
uniq -ci | sed 's/[[:space:]]*//'
Is also the same
uniq -c puts 6 spaces infront of output, but do not use cut -c7- with it to clean the output as these spaces are reserved for the count of lines. If the count exceeds 9 -c7- would only give unit place of the count. use sed 's/^[[:space:]]*//g' its more robust
uniq -i -c | tr -s " " | cut -c2-
uniq -ci | cut -c7-