I'm almost there... I'm supposed to end up with is 340 unique services. So far, I can only get it down to 341.
These are my tasks:
- Extract all the service names from the file.
- Sort the names alphabetically removing any duplicates.
- Remove any blank lines or lines that do not contain letters of the alphabet.
- Capture the final output to a file named 'uniqueservices.txt'.
- Count the lines in the file using a conditional command that is only executed if the previous combined commands are successful.
This is the command I used:
cat /etc/services | grep -Ev '^#|^$' | cut -f1 | sort -u > uniqueservices.txt && wc -l uniqueservices.txt
Here's what I should get:
This is what I actually get:
I'm guessing there are (as always) better ways of doing this but... hey, I'm new to this. So close though!
Thanks in advance.
S
CodePudding user response:
The cut -f1
part of your command determines what "column 1" means by scanning the lines for TAB separators. The unmatched line you're seeing likely just uses a space character instead.
I suppose the easiest thing to do would be to just run cut
again but looking for spaces instead of TABs.
cat /etc/services | grep -Ev '^#|^$' | cut -f1 | cut -d' ' -f1 | sort -u > uniqueservices.txt && wc -l uniqueservices.txt