Unix Shell - More awk questions

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2007 > More awk questions





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author More awk questions
Ben

2007-11-21, 7:21 pm

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
Janis Papanagnou

2007-11-21, 7:21 pm

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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com