Operating System - HP-UX
1834208 Members
2655 Online
110066 Solutions
New Discussion

Re: awk help: field separating

 
SOLVED
Go to solution
SM_3
Super Advisor

awk help: field separating

Need some help.

Using awk I want to print the fields of /etc/passwd with a few spaces between each field.

Filed1 Filed2 Field3 etc

How can I do this?

Thanks.
7 REPLIES 7
Enrico P.
Honored Contributor

Re: awk help: field separating

Hi,
awk -F \: '{print $1,$2,$3,$4,$5,$6,$7}' /etc/passwd

Enrico
SM_3
Super Advisor

Re: awk help: field separating

Enrico I get

awk: syntax error near line 1
awk: bailing out near line 1
Paul_481
Respected Contributor

Re: awk help: field separating

Hi SM,

try

#awk -F ":" '{print $1,$2,$3,$4,$5,%6,$7}'


Regards,
Paul
Paul_481
Respected Contributor

Re: awk help: field separating

EDIT:

#awk -F ":" '{print $1,$2,$3,$4,$5,%6,$7}' /etc/passwd
Eknath
Trusted Contributor

Re: awk help: field separating

HI SM,

Try this
#cat /etc/passwd |awk -F ":" '{print $1,$2,$3,$4,$5,$6,$7}'

it works i have tried.

Cheers!!!

eknath
john korterman
Honored Contributor
Solution

Re: awk help: field separating

Hi,
if you want spaces in between the fields, you can try this:
# awk -F: -v tb=" " '{print $1,tb$2,tb$3,tb$4,tb$5,tb$6,tb$7}' /etc/passwd

the above tb="" is a little difficult to show!
But "\t" for tab should also work.

regards,
John K.
it would be nice if you always got a second chance
Muthukumar_5
Honored Contributor

Re: awk help: field separating

You can use like,
awk -F":" '{ print $1tab$2tab$3tab$4tab$5tab$6tab$7tab$8}' tab=" " /etc/passwd

hth.
Easy to suggest when don't know about the problem!