0

from a file (/etc/services) i need to take out all services, exluding all double or more entries per service, exluding lines starting with '#', sort alfabetically and store to a file. After all this was succesful, i need to count the lines. Adn this is where i struggle: to apply the wc -l command... so far i have:

cut -f 1 etc/services | sed ‘/^#/ d‘ | sort | uniq -u > uniqueservices.txt

Could you help me out?

Thanks

2
  • So... wc -l uniqueservices.txt? – Quasímodo Apr 4 '20 at 11:34
  • Watch out, you have non-ASCII quotes for sed. – Quasímodo Apr 4 '20 at 11:35
1

Try this:

cut -f 1 /etc/services | grep -v -E '^[[:space:]]?#' | sort -u > uniqueservices.txt && wc -l uniqueservices.txt
3
  • Hi, the actuall task is this: Count the lines in the file using a conditional command that is only executed if the previous combined commands are successful. So i guess it has to be in command, or is this not psible? – Dave Bulcke Apr 4 '20 at 11:44
  • 1
    Just add && between the pipeline and wc. – Kusalananda Apr 4 '20 at 11:47
  • Thanks GMaster and Kusalananda! – Dave Bulcke Apr 4 '20 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.