-1

My problem is to extract text from lines in /etc/passwd matching a specific pattern

Only text before the ":*" needs to be selected each line

I want the output seperated by commas.

Here's an example:

dog:*dsfgfdh

cat:*bsdfsdf

To:

dog, cat

I have tried something like this which obviously doesnt work

cat /etc/passwd | grep 'a patern'

Anyone with more understanding of grep wanting to help?

1 Answers1

0

Quick & Dirty:

awk -F':' -v ORS=", " '$0=$1' /etc/passwd

It is "dirty" because the result leaves a comma , at the end. Also there is no newline at the end.

A better version:

awk -F':' '{printf "%s%s", NR==1?"":", ", $1}END{print ""}' /etc/passwd
Kent
  • 173,042
  • 30
  • 210
  • 270