More awk questions

More awk questions

am 21.11.2007 21:01:08 von Ben Jackson

Hi again,

I have a file with a bunch of usernames in a single line per group (/var/etc/group) - I want to
extract each group to another file in columnar format. This is what I got so far:

cat group | grep group1 > group1.file
awk '{FS=","};{print $1}' group1.file

Awk gives me the first username but not the subsequent ones...I think I need a variable defined, but
I don't know how to pass it to awk.

Any sugesstions?

TIA, Ben

p.s. group1.file is comma delimited

Re: More awk questions

am 21.11.2007 21:18:31 von Janis Papanagnou

Ben wrote:
> Hi again,
>
> I have a file with a bunch of usernames in a single line per group
> (/var/etc/group) - I want to extract each group to another file in
> columnar format. This is what I got so far:
>
> cat group | grep group1 > group1.file
> awk '{FS=","};{print $1}' group1.file
>
> Awk gives me the first username but not the subsequent ones...I think I
> need a variable defined, but I don't know how to pass it to awk.
>
> Any sugesstions?
>
> TIA, Ben
>
> p.s. group1.file is comma delimited

The file is formatted like this...?

group1,abc,def,ghi
group2,jkl,mno,pqr

Then try...

awk -F, 'BEGIN{OFS="\n"} /group1/{$1=$1;print}' /var/etc/group


Janis