JavaRed
JavaRed

Reputation: 708

Awk input and output file delimiter

I try to parse a column delimited password file using awk and put hostname in the beginning and add some fields. I need a comma separated output. So what I try is:

/usr/xpg4/bin/awk -F':'  MYHOST=$(hostname)  'BEGIN{OFS=",";} {print MYHOST, $1, $3, $4, $5;}'  /etc/passwd

But this command didn't produce output I wanted. This is a Solaris box, regular awk didn't work so I try with /usr/xpg4/bin/awk

Upvotes: 0

Views: 1210

Answers (1)

Kent
Kent

Reputation: 195209

this may help you:

/usr/xpg4/bin/awk -F':'  -v MYHOST="$(hostname)"  'BEGIN{OFS=","} {print MYHOST, $1, $3, $4, $5;}'  /etc/passwd

Upvotes: 1

Related Questions